Nothing Special   »   [go: up one dir, main page]

MCQ

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 16

MCQ

What will be the output of the program?


#include<stdio.h>
Void main()
{
int i=10, j;
j = ++i;
printf("j =%d", j);

}
What is output of following code:
#include<stdio.h>
void main()
{
int number=31;
int half;
half= number % 2;
printf ( “%d”, half);
}
• In C, which symbols are used for comments?
A. //
B. \\
C. /* and */
D. \c
#include <stdio.h>
int main()
{
int i = 3;
switch (i)
{
case 0+1: printf("Geeks");
break;
case 1+2: printf("Quiz");
break;
default: printf("GeeksQuiz");
}
return 0;
}
What is the output of the above program?
A Geeks
B Quiz
C GeeksQuiz
#include <stdio.h>
int main()
{
int i;
if (printf("0"))
i = 3;
else
i = 5;
printf("%d", i);
return 0;
}
Predict the output of above program?
A3
B5
C 03
D 05
What will be the output of the following C program segment? (GATE CS 2012)
char inchar = 'A';
switch (inchar)
{
case 'A' :
printf ("choice A \n") ;
case 'B' :
printf ("choice B ") ;
case 'C' :
case 'D' :
case 'E' :
default:
printf ("No Choice") ;
}
A No choice
B Choice A
C Choice A
Choice B
No choice
D Program gives no output as it is erroneous
#include<stdio.h>
int main()
{
int a = 5;
switch(a)
{
default:
a = 4;
case 6:
a--;
case 5:
a = a+1;
case 1:
a = a-1;
}
printf("%d n", a);
return 0;
}

A3
B4
C5
D None of these
Consider the following statements:
int x = 22,y=15;
x = (x>y) ? (x+y) : (x-y);
What will be the value of x after executing these
statements?
(A) 22
(B) 37
(C) 7
(D) Error. Cannot be executed
What is the output of the below program?
#include <stdio.h>
int main()
{
int i = 0;
switch (i)
{

default: printf("HelloIndia");
break;
case '0': printf("Hello");
break;
case '1': printf("India");
break;

}
return 0;
}
A. Hello
B. India
C. HelloIndia
D. Compiler Error
#include <stdio.h>
int main()
{
int x = 3;
if (x == 2);
x = 0;
if (x == 3)
x++;
else x += 2;

printf("x = %d", x);

return 0;
}
A. x=4
B. x=2
C. x=0
Error
Which combination of the integer variables x, y
and z makes the variable a get the value 4 in
the following expression?
a = ( x > y ) ? (( x > z ) ? x : z) : (( y > z ) ? y : z )

A. x = 3, y = 4, z = 2
B. x = 6, y = 5, z = 3
C. x = 6, y = 3, z = 5
x = 5, y = 4, z = 5
• Which of the following statement is correct for switch
controlling expression?

A. Only int can be used in “switch” control expression


B. Both int and char can be used in “switch” control
expression
C. All types i.e. int, char and float can be used in
“switch” control expression
D. “switch” control expression can be empty as well
Consider the following program fragment
if(a > b)
if(b > c)
s1;
else s2;

s2 will be executed if

A. a <= b
B. b>c
C. b >= c and a <= b
D. a > b and b <= c
What is the output of the following code?
Void main()
{
int c=0, d=5,e=10,a;
a=c>1?d>1||e>1?100:200:300;
printf(“a=%d”,a);
}

A. a=300
B. a=200
C. a=100
D. None
What is the output of this C code?
#include <stdio.h> I
nt main()
{ int a = 2;
int b = 0;
int y = (b == 0) ? a :(a > b) ? (b = 1): a;
printf("%d\n", y);
}
A. 1
B. 2
C. 3
D. 4

You might also like