C Programming MCQ

1:

The following program fragment

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


results in

A.

a syntax error

B.

an execution error

C.

printing of 12

D.

printing of 15

 

Answer : D

Explanation :

Alok Gupta said: (7:11pm on Friday 26th April 2013)
I think it should print 12 as, there is no equality sign with condition 'i<15' so, when i become 15, this condition become false and loop breaks. Second thing that I need to ask is, does this printf statement is within for loop or outside the loop. If it is inside the loop, then it will print multiple outputs and that should be '3' '6' '9' and '12'. If it is outside then yes it will print 15 but then you should at-least use delimiter to signify that.
Alok Gupta said: (7:13pm on Friday 26th April 2013)
And yes it will results in the syntax error as, at the end of the for loop there is one semi-colon and that is incorrect.

Write your comments here:


Report Error
 

Option: A

Explanation : Explanation will come here. Explanation will come here. Explanation will come here. Explanation will come here. Explanation will come here.