C Questions and Answers Part-16

1. What will be the output of the following C code?
#include < stdio.h >
int main()
{
int *p = NULL;
for (foo(); p; p = 0)
printf("In for loop\n");
printf("After loop\n");
}
a) In for loop after loop
b) Compile time error
c) Infinite loop
d) Depends on the value of NULL

Answer: b

2. What will be the output of the following C code?
#include < stdio.h >
int main()
{
for (int i = 0;i < 1; i++)
printf("In for loop\n");
}
a) Compile time error
b) In for loop
c) Depends on the standard compiler implements
d) Depends on the compiler

Answer: c

3. What will be the output of the following C code?
#include < stdio.h >
int main()
{
while ()
printf("In while loop ");
printf("After loop\n");
}
a) In while loop after loop
b) After loop
c) Compile time error
d) Infinite loop

Answer: c

4. What will be the output of the following C code?
#include < stdio.h >
int main()
{
do
printf("In while loop ");
while (0);
printf("After loop\n");
}
a) In while loop
b) In while loop after loop
c) After loop
d) Infinite loop

Answer: b

5. What will be the output of the following C code?
#include < stdio.h >
int main()
{
int i = 0;
do {
i++;
printf("In while loop\n");
} while (i < 3);
}
a) In while loop
In while loop
In while loop
b) In while loop
In while loop
c) Depends on the compiler
d) Compile time error

Answer: a

6. How many times i value is checked in the following C code?
#include < stdio.h >
int main()
{
int i = 0;
do {
i++;
printf("in while loop\n");
} while (i < 3);
}
a) 2
b) 3
c) 4
d) 1

Answer: b

7. How many times i value is checked in the following C code?
#include < stdio.h >
int main()
{
int i = 0;
while (i < 3)
i++;
printf("In while loop\n");
}
a) 2
b) 3
c) 4
d) 1

Answer: c

8. What will be the output of the following C code?
#include < stdio.h >
void main()
{
int i = 2;
do
{
printf("Hi");
} while (i < 2)
}
a) Compile time error
b) Hi Hi
c) Hi
d) Varies

Answer: a

9. What will be the output of the following C code?
#include < stdio.h >
void main()
{
int i = 0;
while (++i)
{
printf("H");
}
}
a) H
b) H is printed infinite times
c) Compile time error
d) Varies

Answer: b

10. What will be the output of the following C code?
#include < stdio.h >
void main()
{
int i = 0;
do
{
printf("Hello");
} while (i != 0);
}
a) Nothing
b) H is printed infinite times
c) Hello
d) Run time error

Answer: c