Control Flow in C - Placement questions
1. Which is the correct statement?a) Printf(“Maximum = %d\n”, (x.y) ? x : y);
b) Printf( “%s\n”, (mark >= 60) ? “First class” : “Not first class” );
c) Printf(“%s\n”, PASS);
d) All of the above
View Answer / Hide Answer2. do-while loop terminates when conditional expression returns?a) Zero
b) One
c) Non-zero
d) -1
View Answer / Hide Answer3. In the following loop construct, which one is executed only once always.for ( exp1; exp2; exp3) {. . . }
a) exp1
b) exp3
c) exp1 and exp3
d) exp1, exp2 and exp3
View Answer / Hide Answer4. if default statement is omitted and there is no match with the case tablea) No statement within switch case will be executed
b) Syntax error is produced
c) Executes all the statements in the switch case construct
d) Executes the last case statement only
View Answer / Hide Answer5. main()
{
int a = 2, b = 4, c = 8, x = 4;
if ( x == b) x = a; else x = b;
if( x != b) c = c + b; else c = c + a;
printf(“c = %d\n”,c);
}
What will be printed when the above code is executed?
a) C = 4
b) C = 8
c) C = 10
d) C = 12
View Answer / Hide Answer6. main()
{
unsigned int x = -10; int y = 10;
If ( y <= x) printf( “He is good\n”);
If ( y == ( x = -10)) printf( “She is better\n”);
If (( int) x == y) printf(“it is the best\n”);
}
What will be the output of above sample code?
a) She is better
b) He is good it is the best
c) It is the best
d) He is good
View Answer / Hide Answer7. main()
{
int x;
if ( x > 4) printf( “Brinda”);
else if ( x > 10) printf( “Karthik”);
else if ( x > 21 ) printf(“ Pradeep”);
else printf( “Sandeep”);
}
What will be the value of x so that “Karthik” will be printed?
a) From 10 to 21
b) From 11 to 21
c) Grater then 10
d) None
View Answer / Hide Answer8. main()
{
int x = 0;
for (; ;)
{
if ( x++ == 4) break;
continue;
}
printf(“x = %d\n”, x);
}
What will be printed when the above code is executed?
a) X = 0
b) X = 1
c) X = 4
d) X = 5
View Answer / Hide Answer9. What is the output of the following code?main()
{
int I = 0;
switch ( I )
{
case 0 : i++;
case 1 : i+++2
case2 : ++I;
}
printf(“%d”, i++);
}
a) 1
b) 3
c) 4
d) 5
View Answer / Hide Answer10. main()
{
int ones, twos, threes, others;
int c;
Ones = twos = threes = others = 0;
while( ( c = getchar() != ‘\n’) )
{
switch( c )
{
case ‘1’ : ++ones;
case ‘2’ : ++twos;
case ‘3’ : ++threes;
break;
default: ++others;
break;
}
}
printf( “%d%d ”, ones, others);
}
If the input is “1a1b1c” what is the output?
a) 13
b) 34
c) 33
d) 31
View Answer / Hide Answer11. What will be the output of the following code?main()
{
ch = ‘A’;
while (ch <= ‘F’)
{
switch(ch)
{
case’A’: case’B’:case’C’: case’D’: ch++;continue;
case ‘E’: case ‘F’: ch++;
}
putchar( ch );
}
}
a) ABCDEF
b) EFG
c) FG
d) Error
View Answer / Hide Answer12. What is the output of the following code?main()
{
int I = 3;
while( I --)
{
int I = 100;
i- -;
printf(“%d. .”, i);
}
}
a) Infinite loop
b) Error
c) 99..99..99..
d) 3..2..1..
View Answer / Hide Answer13. unsigned char c;
for( c = 0; c != 256; c+2 )
printf(“%d”, c);
Who many times the loop executes?
a) 127
b) 128
c) 256
d) Infinitely
View Answer / Hide Answer14. What is the value of int variable result if x = 50, y = 75 and z = 100?
result = ( x + 50 ? y >=75 ? z > 100 ? 1 : 2 : 3 : 4);
a) 1
b) 2
c) 3
d) 4
View Answer / Hide Answer15. main()
{
int a = -4, r, num = 1;
r = a % -3;
r = ( r ? 0 : num * num);
printf( “%d”, r);
}
What will be the output of the program?
a) 0
b) 1
c) –ve is not allowed in the mod operands
d) None
View Answer / Hide Answer16. main()
{
unsigned int I = 10;
while( i- - >= 0);
}
How many times the loop will be executed?
a) 10
b) Zero times
c) One time
d) None
View Answer / Hide Answer17. switch ( s )
{
case 1 : printf(“Balan”);
case 2:
case 3: printf( “Elango”);
case 4: printf( “Thiruvalluvan”);
default : printf(“Kamban”);
}
To print only Kamban, what will be the value of s?
a) 2
b) 1 or 3 or 4
c) Any int value other then 1,2,3 and 4
d) 4
View Answer / Hide Answer18. How many x are printed?for( I = 0, j = 10; I < j; I ++, j --)
printf(“x”);
a) 10
b) 5
c) 4
d) None
View Answer / Hide Answer19. Identify the wrong statement where - - - - represent C codea) lable : { - - - } - - - - goto lable;
b) goto end; - - -
end : { - - - }
c) goto 50; - - -
50: { - - -}
d) begin: { - - -}
If ( a < 10 ) goto begin;
View Answer / Hide Answer20. What will be the final values of I and j when the following code terminates?main()
{
static int I , j = 5;
for ( I = 0; I < 3; I ++)
{
printf(“%d%d\n”, I, j);
if( j > 1){ j - -; main ();}
}
}
a) 02
b) 11
c) 21
d) Error, because main cannot be called recursively
View Answer / Hide Answer