Classical

C Programming MCQ - Decision Making & Looping

31:  

If switch feature is used, then

A.

default case must be present

B.

default case, if used, should be the last case

C.

default case, if used, can be placed anywhere

D.

none of the above

 
 

Option: C

Explanation :


32:  

The switch feature

A.

can always be replaced by a nested it-then-else clause

B.

enhances logical clarity

C.

can't always be replaced by a nested if -then-else clause

D.

Both (a) and (b)

 
 

Option: D

Explanation :


33:  

Break statement can be simulated by using

A.

goto

B.

return

C.

exit

D.

any of the above features

 
 

Option: A

Explanation :


34:  

The following program fragment

if (2 < 1)
;
else
x =  (2 < 0) ? printf("one") : printf("four");
printf ("%d",  x);

A.

prints nothing

B.

results in a syntax error

C.

prints four 0

D.

none of the above

 
 

Option: D

Explanation :

here else clause will be executed . Since 2 < 0 is false , 4 will be printed 


35:  

Consider the following program fragment

if (a>b)
   printf("a>b");
else
   printf("else part");
   printf("a<=b");


a<=b will be printed if

A.

a>b

B.

a<b

C.

a==b

D.

none of above

 
 

Option: C

Explanation :

The else clause has no brackets i.e., { and }. This means the else clause is made up of only one statement. So, printf( " a < = b" ) will be executed anyway, i.e. if a > b or a <= b. Hence the answer.




Suggest an improvement