0% found this document useful (0 votes)
2K views

Break and Continue MCQ Ans

The document contains 7 multiple choice questions about the break and continue keywords in C programming. It tests understanding of how break exits the current loop or switch completely while continue exits the current iteration and continues with the next. The questions cover different looping structures like for, while, do-while and switch cases, and scenarios involving nested loops. Correct answers are provided for each question.

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)
2K views

Break and Continue MCQ Ans

The document contains 7 multiple choice questions about the break and continue keywords in C programming. It tests understanding of how break exits the current loop or switch completely while continue exits the current iteration and continues with the next. The questions cover different looping structures like for, while, do-while and switch cases, and scenarios involving nested loops. Correct answers are provided for each question.

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/ 11

Break and Continue

1. Which keyword can be used for coming out of recursion?


a) break
b) return
c) exit
d) both break and return

Answer: b

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

1. #include <stdio.h>

2. int main()

3. {

4. int a = 0, i = 0, b;

5. for (i = 0;i < 5; i++)

6. {

7. a++;

8. continue;

9. }

10. }

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

Answer: d

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

1. #include <stdio.h>

2. int main()
3. {

4. int a = 0, i = 0, b;

5. for (i = 0;i < 5; i++)

6. {

7. a++;

8. if (i == 3)

9. break;

10. }

11. }

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

Answer: d

4. The keyword ‘break’ cannot be simply used within _________


a) do-while
b) if-else
c) for
d) while

Answer: b

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

1. #include <stdio.h>

2. void main()

3. {

4. int i = 0, j = 0;

5. for (i = 0;i < 5; i++)

6. {

7. for (j = 0;j < 4; j++)

8. {

9. if (i > 1)

10. break;

11. }

12. printf("Hi \n");

13. }

14. }

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

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

1. #include <stdio.h>

2. void main()

3. {

4. int i = 0;
5. int j = 0;

6. for (i = 0;i < 5; i++)

7. {

8. for (j = 0;j < 4; j++)

9. {

10. if (i > 1)

11. continue;

12. printf("Hi \n");

13. }

14. }

15. }

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

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

1. #include <stdio.h>

2. void main()

3. {

4. int i = 0;

5. for (i = 0;i < 5; i++)

6. if (i < 4)

7. {

8. printf("Hello");
9. break;

10. }

11. }

a) Hello is printed 5 times


b) Hello is printed 4 times
c) Hello
d) Hello is printed 3 times

Answer: c

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

1. #include <stdio.h>

2. void main()

3. {

4. int i = 0;

5. if (i == 0)

6. {

7. printf("Hello");

8. continue;

9. }

10. }

a) Hello is printed infinite times


b) Hello
c) Varies
d) Compile time error

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

1. #include <stdio.h>

2. void main()

3. {

4. int i = 0;

5. if (i == 0)

6. {

7. printf("Hello");

8. break;

9. }

10. }

a) Hello is printed infinite times


b) Hello
c) Varies
d) Compile time error

Answer: d

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. {

7. i++;

8. if (i == 2)
9. continue;

10. printf("In while loop ");

11. } while (i < 2);

12. printf("%d\n", i);

13. }

a) In while loop 2
b) In while loop in while loop 3
c) In while loop 3
d) Infinite loop

Answer: a

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

1. #include <stdio.h>

2. int main()

3. {

4. int i = 0, j = 0;

5. for (i; i < 2; i++){

6. for (j = 0; j < 3; j++)

7. {

8. printf("1\n");

9. break;

10. }

11. printf("2\n");

12. }

13. printf("after loop\n");

14. }
a)

after loop

b)

after loop

c)

after loop

d)

after loop

Answer: c

 
 

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

1. #include <stdio.h>

2. int main()
3. {

4. int i = 0;

5. while (i < 2)

6. {

7. if (i == 1)

8. break;

9. i++;

10. if (i == 1)

11. continue;

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

13. }

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

15. }

a)

In while loop

After loop

b) After loop
c)

In while loop

In while loop

After loop

d) In while loop

Answer: b

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

1. #include <stdio.h>
2. int main()

3. {

4. int i = 0;

5. char c = 'a';

6. while (i < 2)

7. {

8. i++;

9. switch (c)

10. {

11. case 'a':

12. printf("%c ", c);

13. break;

14. break;

15. }

16. }

17. printf("after loop\n");

18. }

a) a after loop
b) a a after loop
c) after loop
d) error

Answer: b

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

1. #include <stdio.h>

2. int main()
3. {

4. printf("before continue ");

5. continue;

6. printf("after continue\n");

7. }

a) Before continue after continue


b) Before continue
c) After continue
d) Compile time error

Answer: d

You might also like