C Programming Questions and Answers on Goto & Labels for Freshers

https://www.computersprofessor.com/2017/12/c-programming-questions-and-answers-on.html
1. What is the output of the code given below?
#include
int main()
{
printf("%d ", 1);
goto l1;
printf("%d ", 2);
l1:goto l2;
printf("%d ", 3);
l2:printf("%d ", 4);
}
a) 1 4
b) Compilation error
c) 1 2 4
d) 1 3 4
b) Compilation error
c) 1 2 4
d) 1 3 4
Answer: a
2. What is the output of code given below?
#include
int main()
{
printf("%d ", 1);
l1:l2:
printf("%d ", 2);
printf("%d\n", 3);
}
a) Compilation error
b) 1 2 3
c) 1 2
d) 1 3
b) 1 2 3
c) 1 2
d) 1 3
Answer: b
3. What is the output of code given below?
#include
int main()
{
printf("%d ", 1);
goto l1;
printf("%d ", 2);
}
void foo()
{
l1 : printf("3 ", 3);
}
a) 1 2 3
b) 1 3
c) 1 3 2
d) Compilation error
b) 1 3
c) 1 3 2
d) Compilation error
Answer: d
4. What is output of code given below?
#include
int main()
{
int i = 0, j = 0;
while (i < 2)
{
l1 : i++;
while (j < 3)
{
printf("Loop\n");
goto l1;
}
}
}
a) Loop Loop
b) Compilation error
c) Loop Loop Loop Loop
d) Infinite Loop
b) Compilation error
c) Loop Loop Loop Loop
d) Infinite Loop
Answer: d
5. What is the output of code given below?
#include
int main()
{
int i = 0, j = 0;
while (l1: i < 2)
{
i++;
while (j < 3)
{
printf("loop\n");
goto l1;
}
}
}
a) loop loop
b) Compilation error
c) loop loop loop loop
d) Infinite loop
b) Compilation error
c) loop loop loop loop
d) Infinite loop
Answer: b
6. What is the output of the code given below?
#include
int main()
{
int i = 0, j = 0;
l1: while (i < 2)
{
i++;
while (j < 3)
{
printf("loop\n");
goto l1;
}
}
}
a) loop loop
b) compilation error
c) oop loop loop loop
d) infinite loop
b) compilation error
c) oop loop loop loop
d) infinite loop
Answer: a
7. The output of the code below is
#include
void main()
{
int i = 0;
if (i == 0)
{
goto label;
}
label: printf("Hello");
}
a) Nothing
b) Error
c) Infinite Hello
d) Hello
b) Error
c) Infinite Hello
d) Hello
Answer: d
8. The output of the code below is
#include
void main()
{
int i = 0, k;
if (i == 0)
goto label;
for (k = 0;k < 3; k++)
{
printf("hi\n");
label: k = printf("%03d", i);
}
}
a) 0
b) hi hi hi 0 0 0
c) 0 hi hi hi 0 0 0
d) 0 0 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
#include
void main()
{
int i = 0, k;
label: printf("%d", i);
if (i == 0)
goto label;
}
a) 0
b) Infinite 0
c) Nothing
d) Error
b) Infinite 0
c) Nothing
d) Error
Answer: b
10. What is the output of this C code?
#include
void main()
{
int i = 5, k;
if (i == 0)
goto label;
label: printf("%d", i);
printf("Hey");
}
a) 5
b) Hey
c) 5 Hey
d) Nothing
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?
#include
int main()
{
printf("%d ", 1);
goto l1;
printf("%d ", 2);
l1:goto l2;
printf("%d ", 3);
l2:printf("%d ", 4);
}
a) 1 4
b) Compile time error
c) 1 2 4
d) 1 3 4
b) Compile time error
c) 1 2 4
d) 1 3 4
Answer: a
13. What is the output of this C code?
#include
int main()
{
printf("%d ", 1);
l1:l2:
printf("%d ", 2);
printf("%d\n", 3);
}
a) Compile time error
b) 1 2 3
c) 1 2
d) 1 3
b) 1 2 3
c) 1 2
d) 1 3
Answer: b
14. What is the output of this C code?
#include
int main()
{
printf("%d ", 1);
goto l1;
printf("%d ", 2);
}
void foo()
{
l1: printf("3 ", 3);
}
a) 1 2 3
b) 1 3
c) 1 3 2
d) Compile time error
b) 1 3
c) 1 3 2
d) Compile time error
Answer: d
15. What is the output of this C code?
#include
int main()
{
int i = 0, j = 0;
while (i < 2)
{
l1: i++;
while (j < 3)
{
printf("loop\n");
goto l1;
}
}
}
a) loop loop
b) Compile time error
c) loop loop loop loop
d) Infinite loop
b) Compile time error
c) loop loop loop loop
d) Infinite loop
Answer: d
16. What is the output of this C code?
#include
int main()
{
int i = 0, j = 0;
while (l1: i < 2)
{
i++;
while (j < 3)
{
printf("loop\n");
goto l1;
}
}
}
a) loop loop
b) Compile time error
c) loop loop loop loop
d) Infinite loop
b) Compile time error
c) loop loop loop loop
d) Infinite loop
Answer: b
17. What is the output of this C code?
#include
int main()
{
int i = 0, j = 0;
l1: while (i < 2)
{
i++;
while (j < 3)
{
printf("loop\n");
goto l1;
}
}
}
a) loop loop
b) Compile time error
c) loop loop loop loop
d) Infinite loop
b) Compile time error
c) loop loop loop loop
d) Infinite loop
Answer: a