Skip to content
Related Articles
Open in App
Not now

Related Articles

C Quiz – 104 | Question 1

Improve Article
Save Article
  • Difficulty Level : Medium
  • Last Updated : 08 Nov, 2021
Improve Article
Save Article

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)<br>
for (i < 10; i++ ; i = 0) // (ii)<br>
for (i = 0; i < 10 ; i++) // (iii)<br>
for (i = 0; i++ ; i < 10) // (iv)<br>
for (i++; i = 0 ; i < 10) // (v)<br>
for (i++; i < 0 ; i = 10) // (vi)<br>


(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

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!