Skip to content
Related Articles
Open in App
Not now

Related Articles

C Quiz – 104 | Question 2

Improve Article
Save Article
  • Difficulty Level : Basic
  • 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 = 0; i < 10 ; i++) // (i)<br>
for ( ; i < 10 ; i++) // (ii)<br>
for (i = 0;  ; i++) // (iii)<br>
for (i = 0; i < 10 ; ) // (iv)<br>
for ( ; ; ) // (v)<br>

(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.

Answer: (D)

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

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!