C Programming Questions and Answers – Goto & Labels – 1

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Goto & Labels – 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.         printf("%d ", 1);
  5.         goto l1;
  6.         printf("%d ", 2);
  7.         l1:goto l2;
  8.         printf("%d ", 3);
  9.         l2:printf("%d ", 4);
  10.    }

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

Answer: a
Explanation: None.
advertisement
advertisement

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

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         printf("%d ", 1);
  5.         l1:l2:
  6.         printf("%d ", 2);
  7.         printf("%d\n", 3);
  8.     }

a) Compilation error
b) 1 2 3
c) 1 2
d) 1 3
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.         printf("%d ", 1);
  5.         goto l1;
  6.         printf("%d ", 2);
  7.     }
  8.     void foo()
  9.     {
  10.         l1 : printf("3 ", 3);
  11.     }

a) 1 2 3
b) 1 3
c) 1 3 2
d) Compilation error
View Answer

Answer: d
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, j = 0;
  5.         while (i < 2)
  6.         {
  7.             l1 : i++;
  8.             while (j < 3)
  9.             {
  10.                 printf("Loop\n");
  11.                 goto l1;
  12.             }
  13.         }
  14.     }

a) Loop Loop
b) Compilation error
c) Loop Loop Loop Loop
d) Infinite Loop
View Answer

Answer: d
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, j = 0;
  5.         while (l1: i < 2)
  6.         {
  7.             i++;
  8.             while (j < 3)
  9.             {
  10.                 printf("loop\n");
  11.                 goto l1;
  12.             }
  13.         }
  14.     }

a) loop loop
b) Compilation error
c) loop loop loop loop
d) Infinite loop
View Answer

Answer: b
Explanation: None.

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

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int i = 0, j = 0;
  5.         l1: while (i < 2)
  6.         {
  7.             i++;
  8.             while (j < 3)
  9.             {
  10.                 printf("loop\n");
  11.                 goto l1;
  12.             }
  13.         }
  14.     }

a) loop loop
b) compilation error
c) oop loop loop loop
d) infinite loop
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.         if (i == 0)
  6.         {
  7.             goto label;
  8.         }
  9.         label: printf("Hello");
  10.     }

a) Nothing
b) Error
c) Infinite Hello
d) Hello
View Answer

Answer: d
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, k;
  5.         if (i == 0)
  6.             goto label;
  7.             for (k = 0;k < 3; k++)
  8.             {
  9.                 printf("hi ");
  10.                 label: k = printf("%03d", i);
  11.             }
  12.     }

a) 0
b) hi hi hi 000
c) 0 hi hi hi 000
d) 000
View Answer

Answer: d
Explanation: None.

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

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int i = 0, k;
  5.         label: printf("%d", i);
  6.         if (i == 0)
  7.             goto label;
  8.     }

a) 0
b) Infinite 0
c) Nothing
d) Error
View Answer

Answer: b
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.