Here is a listing of online C test questions on “While Loops” along with answers, explanations and/or solutions:
1. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
while ()
-
printf("In while loop ");
-
printf("After loopn");
-
}
a) In while loop after loop
b) After loop
c) Compile time error
d) Infinite loop
Answer: c
Clarification: None.
2. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
do
-
printf("In while loop ");
-
while (0);
-
printf("After loopn");
-
}
a) In while loop
b)
In while loop after loop
c) After loop
d) Infinite loop
Answer: b
Clarification: None.
3. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
int i = 0;
-
do {
-
i++;
-
printf("In while loopn");
-
} 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
Clarification: None.
4. How many times i value is checked in the following C code?
-
#include
-
int main()
-
{
-
int i = 0;
-
do {
-
i++;
-
printf("in while loopn");
-
} while (i < 3);
-
}
a) 2
b) 3
c) 4
d) 1
Answer: b
Clarification: None.
5. How many times i value is checked in the following C code?
-
#include
-
int main()
-
{
-
int i = 0;
-
while (i < 3)
-
i++;
-
printf("In while loopn");
-
}
a) 2
b) 3
c) 4
d) 1
Answer: c
Clarification: None.
6. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
int i = 2;
-
do
-
{
-
printf("Hi");
-
} while (i < 2)
-
}
a) Compile time error
b) Hi Hi
c) Hi
d) Varies
Answer: a
Clarification: None.
7. What will be the output of the following C code?
-
#include
-
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
Clarification: None.
8. What will be the output of the following C code?
-
#include
-
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
Clarification: None.