Skip to content
Related Articles
Open in App
Not now

Related Articles

C Quiz – 104 | Question 4

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

What’s going to happen when we compile and run the following C program?

#include < stdio.h ><br>
int main()<br>
 int j = 0;<br>
 for ( ; j < 10 ; )<br>
 { <br>
   if (j < 10)<br>
     printf("Geeks", j++);<br>
 return 0;<br>

(A) Compile Error due to use of continue in for loop.
(B) No compile error but it will run into infinite loop printing Geeks.
(C) No compile error and it’ll print GeeksQuiz 10 times followed by Quiz once.
(D) No compile error and it’ll print GeeksQuiz 10 times.

Answer: (D)

Explanation: Here, initialization of j has been done outside for loop. if condition serves as control statement and prints GeeksQuiz 10 times due to two printfs. Please note that continue comes in picture when j becomes 10. At that time, second printf gets skipped and second expression in for is checked and it fails. Due to this, for loop ends.

Quiz of this Question

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!