0% found this document useful (0 votes)
943 views5 pages

While Loop MCQ Ans

The document discusses while loops in C programming. It provides 8 multiple choice questions about the output of various while and do-while loop code snippets. The questions test different aspects of while and do-while loop execution, such as whether the condition is checked before or after loop execution, and how many times the condition will be checked. The correct answers are also provided.

Uploaded by

nancy_007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
943 views5 pages

While Loop MCQ Ans

The document discusses while loops in C programming. It provides 8 multiple choice questions about the output of various while and do-while loop code snippets. The questions test different aspects of while and do-while loop execution, such as whether the condition is checked before or after loop execution, and how many times the condition will be checked. The correct answers are also provided.

Uploaded by

nancy_007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

While Loop

1. What will be the output of the following C code?

1. #include <stdio.h>

2. int main()

3. {

4. while ()

5. printf("In while loop ");

6. printf("After loop\n");

7. }

a) In while loop after loop


b) After loop
c) Compile time error
d) Infinite loop

Answer: c

2. What will be the output of the following C code?

1. #include <stdio.h>

2. int main()

3. {

4. do

5. printf("In while loop ");

6. while (0);

7. printf("After loop\n");

8. }

a) In while loop
b)

In while loop

after loop

c) After loop
d) Infinite loop
Answer: b

3. What will be the output of the following C code?

1. #include <stdio.h>

2. int main()

3. {

4. int i = 0;

5. do {

6. i++;

7. printf("In while loop\n");

8. } while (i < 3);

9. }

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

4. How many times i value is checked in the following C code?

1. #include <stdio.h>

2. int main()

3. {

4. int i = 0;

5. do {

6. i++;
7. printf("in while loop\n");

8. } while (i < 3);

9. }

a) 2
b) 3
c) 4
d) 1

Answer: b

5. How many times i value is checked in the following C code?

1. #include <stdio.h>

2. int main()

3. {

4. int i = 0;

5. while (i < 3)

6. i++;

7. printf("In while loop\n");

8. }

a) 2
b) 3
c) 4
d) 1

Answer: c

6. What will be the output of the following C code?

1. #include <stdio.h>

2. void main()

3. {

4. int i = 2;

5. do

6. {
7. printf("Hi");

8. } while (i < 2)

9. }

a) Compile time error


b) Hi Hi
c) Hi
d) Varies

Answer: a

7. What will be the output of the following C code?

1. #include <stdio.h>

2. void main()

3. {

4. int i = 0;

5. while (++i)

6. {

7. printf("H");

8. }

9. }

a) H
b) H is printed infinite times
c) Compile time error
d) Varies

Answer: b

8. What will be the output of the following C code?

1. #include <stdio.h>

2. void main()

3. {

4. int i = 0;

5. do
6. {

7. printf("Hello");

8. } while (i != 0);

9. }

a) Nothing
b) H is printed infinite times
c) Hello
d) Run time error

Answer: c

You might also like