Skip to content
Related Articles

Related Articles

Improve Article
C Quiz – 104 | Question 1
  • Difficulty Level : Medium
  • Last Updated : 06 Oct, 2015

With respect to following “for” loops in C, pick the best statement Assume that there is a prior declaration of ‘i’ in all cases




for (i < 10; i = 0 ; i++) // (i)
for (i < 10; i++ ; i = 0) // (ii)
for (i = 0; i < 10 ; i++) // (iii)
for (i = 0; i++ ; i < 10) // (iv)
for (i++; i = 0 ; i < 10) // (v)
for (i++; i < 0 ; i = 10) // (vi)

(A) All the above “for” loops would compile successfully.
(B) All the above “for” loops would compile successfully. Except (iii), the behaviour of all the other “for” loops depend on compiler implementation.
(C) Only (iii) would compile successfully.
(D) Only (iii) and (iv) would compile successfully.
(E) Only (iii) and (iv) would compile successfully but behaviour of (iv) would depend on compiler implementation.


Answer: (A)

Explanation: Basically, all of the “for” loops are valid i.e. . In the above examples, it doesn’t matter what expression has been put in which part of a “for” loop. The execution order of these expressions remain same irrespective of where they have been put i.e. “1st expression” followed by “2nd expression” followed by “body of the loop” followed by “3rd expression”. But the exact behavior of each of the above “for” loop depends on the body of loop as well. In fact the following is also valid and work without any issue in C. for(printf(“1st”) ; printf(“2nd”) ; printf(“3rd”)) { break; }

Quiz of this Question

Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.
My Personal Notes arrow_drop_up
Recommended Articles
Page :