C Quiz – 104 | Question 4

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

filter_none

edit
close

play_arrow

link
brightness_4
code

#include "stdio.h"
int main()
{
 int j = 0;
 for ( ; j < 10 ; )
 
   if (j < 10)
     printf("Geeks", j++);
   else
     continue;
   printf(“Quiz”);
 }
 return 0;
}

chevron_right


(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


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.