C Questions and Answers Part-19

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

Answer: a

2. What will be the output of the following C code?
#include < stdio.h >
void main()
{
int i = 0;
if (i == 0)
{
goto label;
}
label: printf("Hello");
}
a) Nothing
b) Error
c) Infinite Hello
d) Hello

Answer: d

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

Answer: d

4. What will be the output of the following C code?
#include < stdio.h >
void main()
{
int i = 0, k;
label: printf("%d", i);
if (i == 0)
goto label;
}
a) 0
b) Infinite 0
c) Nothing
d) Error

Answer: b

5. What will be the output of the following C code?
#include < stdio.h >
int main()
{
void foo();
printf("1 ");
foo();
}
void foo()
{
printf("2 ");
}
a) 1 2
b) Compile time error
c) 1 2 1 2
d) Depends on the compiler

Answer: a

6. What will be the output of the following C code?
#include < stdio.h >
int main()
{
void foo(), f();
f();
}
void foo()
{
printf("2 ");
}
void f()
{
printf("1 ");
foo();
}
a) Compile time error as foo is local to main
b) 1 2
c) 2 1
d) Compile time error due to declaration of functions inside main

Answer: b

7. What will be the output of the following C code?
#include < stdio.h >
int main()
{
void foo();
void f()
{
foo();
}
f();
}
void foo()
{
printf("2 ");
}
a) 2 2
b) 2
c) Compile time error
d) Depends on the compiler

Answer: d

8. What will be the output of the following C code?
#include < stdio.h >
void foo();
int main()
{
void foo();
foo();
return 0;
}
void foo()
{
printf("2 ");
}
a) Compile time error
b) 2
c) Depends on the compiler
d) Depends on the standard

Answer: b

9. What will be the output of the following C code?
#include < stdio.h >
void foo();
int main()
{
void foo(int);
foo(1);
return 0;
}
void foo(int i)
{
printf("2 ");
}
a) 2
b) Compile time error
c) Depends on the compiler
d) Depends on the standard

Answer: a

10. What will be the output of the following C code?
#include < stdio.h >
void foo();
int main()
{
void foo(int);
foo();
return 0;
}
void foo()
{
printf("2 ");
}
a) 2
b) Compile time error
c) Depends on the compiler
d) Depends on the standard

Answer: b