C Programming Questions and Answers – While Loops – 1

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

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.     int main()
  3.     {
  4.         while ()
  5.             printf("In while loop ");
  6.         printf("After loop\n");
  7.     }

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

Answer: c
Explanation: None.
advertisement
advertisement

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

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         do
  5.             printf("In while loop ");
  6.         while (0);
  7.             printf("After loop\n");
  8.     }

a) In while loop
b) In while loop After loop
c) After loop
d) Infinite loop
View Answer

Answer: b
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.         do {
  6.             i++;
  7.             printf("In while loop\n");
  8.         } while (i < 3);
  9.     }

a)

   In while loop
   In while loop
   In while loop
advertisement

b)

   In while loop
   In while loop

c) Depends on the compiler
d) Compile time error
View Answer

Answer: a
Explanation: None.

4. How many times i value is checked in the following C code?

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

a) 2
b) 3
c) 4
d) 1
View Answer

Answer: b
Explanation: None.

5. How many times i value is checked in the following C code?

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

a) 2
b) 3
c) 4
d) 1
View Answer

Answer: c
Explanation: None.

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

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int i = 2;
  5.         do
  6.         {
  7.             printf("Hi");
  8.         } while (i < 2)
  9.     }

a) Compile time error
b) Hi Hi
c) Hi
d) Varies
View Answer

Answer: a
Explanation: None.

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

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int i = 0;
  5.         while (++i)
  6.         {
  7.             printf("H");
  8.         }
  9.     }

a) H
b) H is printed infinite times
c) Compile time error
d) Varies
View Answer

Answer: b
Explanation: None.

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

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int i = 0;
  5.         do
  6.         {
  7.             printf("Hello");
  8.         } while (i != 0);
  9.     }

a) Nothing
b) H is printed infinite times
c) Hello
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.