Conditional Statement: GATE CS Previous Year Questions

Conditional Statement · Programming in C

5 questions · asked in 4 of 27 years (2000–2026)

MCQ 3 · NAT 21-mark 2 · 2-mark 3

2000Questions per year2026

Questions 1–5 of 5

Q1GATE 2021 (Session 1)2 marksMCQ−0.67 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?

Q2GATE 2015 (Session 2)2 marksNAT
Consider the C program below.

#include <stdio.h>
int *A, stkTop;
int stkFunc(int opcode, int val)
{
    static int size=0, stkTop=0;
    switch (opcode) {
        case -1: size = val; break;
        case 0: if (stkTop < size) A[stkTop++] = val; break;
        default: if (stkTop) return A[--stkTop];
        }
       return -1;
}
int main()
{
    int B[20]; A = B; stkTop = -1;
    stkFunc (-1, 10);
    stkFunc ( 0, 5);
    stkFunc ( 0, 10);
    printf ("%d\n", stkFunc(1, 0) + stkFunc(1, 0));
}
The value printed by the above program is __________.

Q3GATE 2015 (Session 3)2 marksNAT
Consider the following C program:
#include <stdio.h>
int main( )
{
    int i, j, k = 0;
    j = 2 * 3 / 4 + 2.0 / 5 + 8 / 5;
    k -=  --j;
    for(i = 0; i < 5; i++)
    {
         switch(i + k)
        {
          case 1:
          case 2: printf("\n%d", i+k);
          case 3: printf("\n%d", i+k);
          default: printf("\n%d", i+k);
        }
   }
return 0;
}
The number of times printf statement is executed is ________.

Q4GATE 20121 markMCQ−0.33 if wrong
What will be the output of the following C program segment?
 char inChar = 'A' ;
switch ( inChar ) {
case 'A' : printf ("Choice A\n") ;
case 'B' :
case 'C' : printf ("Choice B") ;
case 'D' :
case 'E' :
default : printf ( " No Choice" ) ; } 

Q5GATE 20041 markMCQ−0.33 if wrong
Let x be an integer which can take a value of 0 or 1. The statement
if (x == 0) x = 1; else x = 0; 
is equivalent to which one of the following ?

Keep practising

Topics in Programming in C

All CS topics ›