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.

advertisement

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?

advertisement
  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
advertisement

c) After loop
d) Infinite loop
View Answer

Answer: b
Explanation: None.

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

advertisement
  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

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.

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!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter

Check his free tutorial videos on Advanced C Programming. Join his Sanfoundry-Classes telegram channel for all videos and queries on Programming, Data-Structures, Kernel, Personality development and Mentoring.