C Quiz – 104 | Question 2
With respect to following “for” loops in C, pick the best statement. Assume that there is a prior declaration of ‘i’ in all cases
(A) Only (i) and (v) would compile successfully. Also (v) can be used as infinite loop.
(B) Only (i) would compile successfully.
(C) All would compile successfully but behavior of (ii), (iii) and (iv) would depend on compiler.
(D) All would compile successfully.
Explanation: In C, any of the 3 expressions of “for” loop can be empty. The exact behavior of the loop depends on the body of the loop as well. Basically, all of the 3 expressions of loop can be put inside the loop body. So as per C language standard, all of the above are valid for loops.
Quiz of this Question