Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

C Quiz – 104 | Question 4

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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




#include < stdio.h ><br>
int main()<br>
{<br>
 int j = 0;<br>
 for ( ; j < 10 ; )<br>
 { <br>
   if (j < 10)<br>
     printf("Geeks", j++);<br>
   else<br>
     continue;<br>
   printf(“Quiz”);<br>
 }<br>
 return 0;<br>
}<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
Last Updated : 08 Nov, 2021
Like Article
Save Article
Similar Reads