Open In App

C Quiz – 104 | Question 4

Like Article
Like
Save
Share
Report

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


Last Updated : 08 Nov, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads