Classical

C Programming MCQ - Decision Making & Looping

21:  

The following Program

main() 
{
int i = 5;
if (i == 5) return;
else printf (" is not five");
printf("over");
}


results in

A.

a syntax error

B.

an execution error

C.

printing of over

D.

execution termination, without printing anything

 
 

Option: D

Explanation :


22:  

The following program fragment

int i = 5;
do
{
putchar(i + 100);
printf("%d", i--);
}
while (i);


results in the printing of

A.

i5h4g3f2el

B.

i4h3g2fle0

C.

an error message

D.

none of above

 
 

Option: A

Explanation :

putchar (1 0 5) will print the ASCII equivalent of 105 i.e.. ' i '. The printf statement prints the current value of i. i.e. 5 and then decrements it. So, h4 will be printed in the next pass. This continues until ' i ' becomes 0, at which point the loop gets terminated.


23:  

The following loop
while(printf("%d", printf("az")))
printf("by");

A.

prints azbybvbvbv...

B.

an execution error

C.

prints azbyazbyazbyazby...

D.

none of the above

 
 

Option: D

Explanation :

printf("az") prints az and returns a value 2 (since it printed two characters). So. the condition results in the printing of az2. Since it always returns 2, it is an infinite loop. The output will be az2byaz2by. . .


24:  

The following statements

for (i= 3; i < 15; i += 3)
{
printf ("%d ", i); 
++i;
}

will result in the printing of

A.

3 6 9 12

B.

3 6 9 12 15

C.

3711

D.

3 7 I I 15

 
 

Option: C

Explanation :


25:  

In a for loop, if the condition is missing, then,

A.

it is assumed to be present and taken to be false

B.

it is assumed to be present and taken to be true

C.

it results in a syntax error

D.

execution will be terminated abruptly

 
 

Option: B

Explanation :




Suggest an improvement