C Expressions and Control Flow questions — page 1 of 2

Q27

GATE CS 2026 CS-1C ProgrammingMSQ1 mark
Consider the following C statements:
char *str1 = "Hello; /* Statement S1 */
char *str2 = "Hello;"; /* Statement S2 */
int *str3 = "Hello"; /* Statement S3 */
Which of the following options is/are correct?
More than one option can be correct.
Show answer without attempting

Answer: C

Q34

GATE CS 2026 CS-1C ProgrammingNAT1 mark
Consider the following program in C:
#include <stdio.h>

void func(int i, int j) {
 if(i < j) {
 int i = 0;
 while (i < 10) {
 j += 2;
 i++;
 }
 }
 printf("%d", i);
}

int main() {
 int i = 9, j = 10;
 func(i, j);
 return 0;
}
The output of the program is _________. (answer in integer)
Note: Assume that the program compiles and runs successfully.
Show answer without attempting

Answer: 9

Q19

GATE CS 2026 CS-2C ProgrammingMCQ1 mark−1/3 if wrong
Consider the following three ANSI-C programs, P1, P2, and P3.
/* P1 */
#include <stdio.h>
int a=5;
int main(){
 int a=7;
 return(0);
}
/* P2 */
#include <stdio.h>
int main(){
 int a=5;
 int a=7;
 return(0);
}
/* P3 */
#include <stdio.h>
int main(){
 int a=5;
 float a=7;
 return(0);
}
Which one of the following statements is true?
Show answer without attempting

Answer: A

Q63

GATE CS 2025 CS-1C ProgrammingNAT2 marks
Consider the following C program:
#include <stdio.h>
int gate (int n) {
 int d, t, newnum, turn;
 newnum = turn = 0; t=1;
 while (n>=t) t *= 10;
 t /=10;
 while (t>0) {
 d = n/t;
 n = n%t;
 t /= 10;
 if (turn) newnum = 10*newnum + d;
 turn = (turn + 1) % 2;
 }
 return newnum;
}
int main () {
 printf ("%d", gate(14362));
 return 0;
}
The value printed by the given C program is _______ . (Answer in integer)
Show answer without attempting

Answer: 46

Q19

GATE CS 2025 CS-2C ProgrammingMCQ1 mark−1/3 if wrong
Consider the following C program:
#include <stdio.h>
void stringcopy(char *, char *);
int main(){
    char a[30] = "@#Hello World!";
    stringcopy(a, a + 2);
    printf("%s\n", a);
    return 0;
}
void stringcopy(char *s, char *t) {
    while(*t)
        *s++ = *t++;
}
Which ONE of the following will be the output of the program?
Show answer without attempting

Answer: D

Q33

GATE CS 2025 CS-2C ProgrammingNAT1 mark
 int x=126,y=105;
 do {
 if(x>y) x=x-y;
 else y=y-x;
 } while(x!=y);
 printf("%d",x);
The output of the given C code segment is ________. (Answer in integer)
Show answer without attempting

Answer: 21

Q18

GATE CS 2024 CS-1C ProgrammingMCQ1 mark−1/3 if wrong
Consider the following C program:
#include <stdio.h>
int main(){
 int a = 6;
 int b = 0;
 while(a < 10) {
 a = a / 12 + 1;
 a += b;
 }
 printf("%d", a);
 return 0;
}
Which one of the following statements is CORRECT?
Show answer without attempting

Answer: C

Q48

GATE CS 2024 CS-1C ProgrammingMSQ2 marks
Consider the following C function definition.
int f(int x, int y) {
 for (int i=0; i<y; i++) {
 x=x+x+y;
 }
 return x;
}
Which of the following statements is/are TRUE about the above function?
More than one option can be correct.
Show answer without attempting

Answer: B, D

Q42

GATE CS 2024 CS-2C ProgrammingMCQ2 marks−2/3 if wrong
Consider an array X that contains n positive integers. A subarray of X is defined to be a sequence of array locations with consecutive indices.

The C code snippet given below has been written to compute the length of the longest subarray of X that contains at most two distinct integers. The code has two missing expressions labelled (P)(P) and (Q)(Q).
int first=0, second=0, len1=0, len2=0, maxlen=0;
for (int i=0; i < n; i++) {
    if (X[i] == first) {
        len2++; len1++;
    } else if (X[i] == second) {
        len2++;
        len1 = (P) ;
        second = first;
    } else {
        len2 = (Q) ;
        len1 = 1; second = first;
    }
    if (len2 > maxlen) {
        maxlen = len2;
    }
    first = X[i];
}
Which one of the following options gives the CORRECT missing expressions?

(Hint: At the end of the i-th iteration, the value of len1 is the length of the longest subarray ending with X[i] that contains all equal values, and len2 is the length of the longest subarray ending with X[i] that contains at most two distinct values.)
Show answer without attempting

Answer: B

Q35

GATE CS 2023 CSC ProgrammingNAT1 mark
The integer value printed by the ANSI-C program given below is ____________.
#include<stdio.h>
int funcp(){
static int x = 1;
x++;
return x;
}
int main(){
int x,y;
x = funcp();
y = funcp()+x;
printf("%d\n", (x+y));
return 0;
}
Show answer without attempting

Answer: 7

Q43

GATE CS 2022 CSC ProgrammingMCQ2 marks−2/3 if wrong
What is printed by the following ANSI C program?
#include<stdio.h>
int main(int argc, char *argv[])
{
  int a[3][3][3] =
  {{1, 2, 3, 4, 5, 6, 7, 8, 9},
   {10, 11, 12, 13, 14, 15, 16, 17, 18},
   {19, 20, 21, 22, 23, 24, 25, 26, 27}};
  int i = 0, j = 0, k = 0;
  for( i = 0; i < 3; i++ ){
    for(k = 0; k < 3; k++ )
      printf("%d ", a[i][j][k]);
    printf("\n");
  }
  return 0;
}
Show answer without attempting

Answer: A

Q44

GATE CS 2022 CSC ProgrammingMCQ2 marks−2/3 if wrong
What is printed by the following ANSI C program?
#include<stdio.h>
int main(int argc, char *argv[]){
  char a = 'P';
  char b = 'x';
  char c = (a & b) + '*';
  char d = (a | b) - '-';
  char e = (a ^ b) + '+';
  printf("%c %c %c\n", c, d, e);
  return 0;
}
ASCII encoding for relevant characters is given below
Question figure
Show answer without attempting

Answer: A

Q37

GATE CS 2021 CS-1C ProgrammingMCQ2 marks−2/3 if wrong
Consider the following ANSI C program.
#include <stdio.h>
int main()
{
    int i, j, count;
    count = 0;
    i = 0;
    for (j = -3; j <= 3; j++)
    {
        if ((j >= 0) && (i++))
            count = count + j;
    }
    count = count + i;
    printf("%d", count);
    return 0;
}
Which one of the following options is correct?
Show answer without attempting

Answer: B

Q48

GATE CS 2021 CS-1C ProgrammingNAT2 marks
Consider the following ANSI C function:
int SimpleFunction(int Y[], int n, int x)
{
  int total = Y[0], loopIndex;
  for (loopIndex = 1; loopIndex <= n - 1; loopIndex++)
       total = x * total + Y[loopIndex];
  return total;
}
Let Z be an array of 10 elements with Z[ii]=1, for all ii such that 0≤i≤90 \le i \le 9. The value returned by SimpleFunction(Z, 10, 2) is ______.
Show answer without attempting

Answer: 1023

Q10

GATE CS 2021 CS-2C ProgrammingMCQ1 mark−1/3 if wrong
Consider the following ANSI C program:
#include <stdio.h>
int main(){
    int arr[4][5];
    int i, j;
    for (i=0; i<4; i++){
        for (j=0; j<5; j++){
            arr[i][j] = 10*i + j;
        }
    }
    printf("%d", *(arr[1] + 9));
    return 0;
}
What is the output of the above program?
Show answer without attempting

Answer: C

Q48

GATE CS 2020 CSC ProgrammingNAT2 marks
Consider the following C functions.
int tob(int b, int* arr) {
    int i;
    for (i=0; b>0; i++) {
        if (b%2) arr[i]=1;
        else     arr[i]=0;
        b = b/2;
    }
    return(i);
}

int pp(int a, int b) {
    int arr[20];
    int i, tot = 1, ex, len;
    ex = a;
    len = tob(b,arr);
    for (i=0; i<len; i++) {
        if (arr[i]==1)
            tot = tot * ex;
        ex = ex * ex;
    }
    return(tot);
}
The value returned by pp(3,4) is __________.
Show answer without attempting

Answer: 81

Q18

GATE CS 2019 CSC ProgrammingNAT1 mark
Consider the following C program:
#include <stdio.h>
int jumble(int x, int y){
    x = 2*x + y;
    return x;
}
int main(){
    int x=2, y=5;
    y = jumble(y,x);
    x = jumble(y,x);
    printf("%d \n", x);
    return 0;
}
The value printed by the program is __________.
Show answer without attempting

Answer: 26

Q27

GATE CS 2019 CSC ProgrammingMCQ2 marks−2/3 if wrong
Consider the following C program:
#include <stdio.h>
int r(){
    static int num=7;
    return num--;
}
int main(){
    for (r();r();r())
        printf("%d",r());
    return 0;
}
Which one of the following values will be displayed on execution of the programs?
Show answer without attempting

Answer: B

Q52

GATE CS 2019 CSC ProgrammingNAT2 marks
Consider the following C program:
#include <stdio.h>
int main(){
    float sum = 0.0, j = 1.0, i = 2.0;
    while (i/j > 0.0625){
        j = j + j;
        sum = sum + i/j;
        printf("%f\n", sum);
    }
    return 0;
}
The number of times the variable sum will be printed, when the above program is executed, is __________.
Show answer without attempting

Answer: 5

Q53

GATE CS 2017 CS-1C ProgrammingNAT2 marks
Consider the following C program.
#include <stdio.h>
#include <string.h>

void printlength(char *s, char *t) {
    unsigned int c = 0;
    int len = ((strlen(s) - strlen(t)) > c) ? strlen(s): strlen(t);
    printf("%d\n", len);
}

void main() {
    char *x = "abc";
    char *y = "defgh";
    printlength(x,y);
}
Recall that strlen is defined in string.h as returning a value of type size_t, which is an unsigned int. The output of the program is ____________.
Show answer without attempting

Answer: 3.0

0/200 correct0 marks

Related topics in C Programming