C Programming Questions and Answers on Goto & Labels for Freshers

1. What is the output of the code given below?

  1.     #include 
  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
Answer: a
2. What is the output of code given below?

  1.     #include 
  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
Answer: b
3. What is the output of code given below?
  1.     #include 
  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
Answer: d
4. What is output of code given below?

  1.     #include 
  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

Answer: d
5. What is the output of code given below?
  1.     #include 
  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
Answer: b
6. What is the output of the code given below?
  1.     #include 
  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
Answer: a
7. The output of the code below is
  1.     #include 
  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
Answer: d
8. The output of the code below is
  1.     #include 
  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\n");
  10.                 label: k = printf("%03d", i);
  11.             }
  12.     }
a) 0
b) hi hi hi 0 0 0
c) 0 hi hi hi 0 0 0
d) 0 0 0
Answer: a
9. The output of the code below is
  1.     #include 
  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
Answer: b
10. What is the output of this C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         int i = 5, k;
  5.         if (i == 0)
  6.             goto label;
  7.             label: printf("%d", i);
  8.             printf("Hey");
  9.     }
a) 5
b) Hey
c) 5 Hey
d) Nothing
Answer: c
11. goto can be used to jump from main to within a function

a) true
b) false
c) depends
d) varies
Answer: b
12. What is the output of this C code?

  1.     #include 
  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) Compile time error
c) 1 2 4
d) 1 3 4
Answer: a
13. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         printf("%d ", 1);
  5.         l1:l2:
  6.         printf("%d ", 2);
  7.         printf("%d\n", 3);
  8.     }
a) Compile time error
b) 1 2 3
c) 1 2
d) 1 3
Answer: b
14. What is the output of this C code?

  1.     #include 
  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) Compile time error
Answer: d
15. What is the output of this C code?

  1.     #include 
  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) Compile time error
c) loop loop loop loop
d) Infinite loop
Answer: d
16. What is the output of this C code?

  1.     #include 
  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) Compile time error
c) loop loop loop loop
d) Infinite loop
Answer: b
17. What is the output of this C code?

  1.     #include 
  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) Compile time error
c) loop loop loop loop
d) Infinite loop
Answer: a

Related

Computer Fundamentals Multiple choice Questions and Answers on The Input Unit for Freshers

1. Which unit is responsible for converting the data received from the user into a computer understandable format? a) Memory Unitb) Arithmetic & Logic Unitc) Input Unitd) Output Unit Answer: c...

Multiple choice Questions and Answers on Server and Instance types of Cloud Computing

1. Which of the following type is missing in the following figure ?a) High-CPUb) High-Diskc) High-ROMd) All of the mentioned Answer: a Explanation: In cloud computing, you can often increase capac...

Multiple choice Questions and Answers on Resource Ceilings of Cloud Computing for Freshers

1. Which of the following resource(s) represents the bottleneck in the current system that limits the system’s performance ? a) ROMb) Resource ceilingc) Resource Parametersd) All of the mentioned ...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item