C Questions and Answers Part-18

1. The keyword ‘break’ cannot be simply used within _________
a) do-while
b) if-else
c) for
d) while

Answer: b

2. Which keyword is used to come out of a loop only for that iteration?
a) break
b) continue
c) return
d) none of the mentioned

Answer: b

3. What will be the output of the following C code?
#include < stdio.h >
void main()
{
int i = 0, j = 0;
for (i = 0;i < 5; i++)
{
for (j = 0;j < 4; j++)
{
if (i > 1)
break;
}
printf("Hi \n");
}
}
a) Hi is printed 5 times
b) Hi is printed 9 times
c) Hi is printed 7 times
d) Hi is printed 4 times

Answer: a

4. What will be the output of the following C code?
#include < stdio.h >
void main()
{
int i = 0;
int j = 0;
for (i = 0;i < 5; i++)
{
for (j = 0;j < 4; j++)
{
if (i > 1)
continue;
printf("Hi \n");
}
}
}
a) Hi is printed 9 times
b) Hi is printed 8 times
c) Hi is printed 7 times
d) Hi is printed 6 times

Answer: b

5. What will be the output of the following C code?
#include < stdio.h >
void main()
{
int i = 0;
for (i = 0;i < 5; i++)
if (i < 4)
{
printf("Hello");
break;
}
}
a) Hello is printed 5 times
b) Hello is printed 4 times
c) Hello
d) Hello is printed 3 times

Answer: c

6. What will be the output of the following C code?
#include < stdio.h >
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

Answer: a

7. What will be the output of the following C code?
#include < stdio.h >
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

Answer: b

8. What will be the output of the following C code?
#include < stdio.h >
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

Answer: d

9. What will be the output of the following C code?
#include < stdio.h >
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

Answer: d

10. What will be the output of the following C code?
#include < stdio.h >
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

Answer: b