Skip to content
Related Articles

Related Articles

C Quiz – 104 | Question 4
  • Difficulty Level : Basic
  • Last Updated : 07 Oct, 2015

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

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

(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

Attention reader! Don’t stop learning now. Get hold of all the important C++ Foundation and STL concepts with the C++ Foundation and STL courses at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :