C Programming Questions and Answers – For Loops – 2

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “For Loops – 2”.

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

1. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         double k = 0;
  5.         for (k = 0.0; k < 3.0; k++);
  6.             printf("%lf", k);
  7.     }

a) 2.000000
b) 4.000000
c) 3.000000
d) Run time error
View Answer

Answer: c
Explanation: None.

2. What will be the output of the following C code?

advertisement
advertisement
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int k;
  5.         for (k = -3; k < -5; k++)
  6.             printf("Hello");
  7.     }

a) Hello
b) Infinite hello
c) Run time error
d) Nothing
View Answer

Answer: d
Explanation: None.
advertisement

3. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int i = 0;
  5.         for (; ; ;)
  6.             printf("In for loop\n");
  7.             printf("After loop\n");
  8.     }

a) Compile time error
b) Infinite loop
c) After loop
d) Undefined behaviour
View Answer

Answer: a
Explanation: None.
advertisement

4. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int i = 0;
  5.         for (i++; i == 1; i = 2)
  6.             printf("In for loop ");
  7.             printf("After loop\n");
  8.     }

a) In for loop after loop
b) After loop
c) Compile time error
d) Undefined behaviour
View Answer

Answer: a
Explanation: None.

5. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int i = 0;
  5.         for (foo(); i == 1; i = 2)
  6.             printf("In for loop\n");
  7.             printf("After loop\n");
  8.     }
  9.     int foo()
  10.     {
  11.         return 1;
  12.     }

a) After loop
b) In for loop after loop
c) Compile time error
d) Infinite loop
View Answer

Answer: a
Explanation: None.

6. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int *p = NULL;
  5.         for (foo(); p; p = 0)
  6.             printf("In for loop\n");
  7.             printf("After loop\n");
  8.     }

a) In for loop after loop
b) Compile time error
c) Infinite loop
d) Depends on the value of NULL
View Answer

Answer: b
Explanation: None.

7. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         for (int i = 0;i < 1; i++)
  5.             printf("In for loop\n");
  6.     }

a) Compile time error
b) In for loop
c) Depends on the standard compiler implements
d) Run time error
View Answer

Answer: c
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.