Site icon T4Tutorials.com

Jump statements: break, continue, goto, return — C++ MCQs

1. What will be the output of this code?
for(int i = 1; i <= 5; i++) {
if(i == 3) break;
cout << i;
}

(A) 1 2


(B) 1 2 3


(C) 1 2 3 4 5


(D) Error



2. What will the code print?
for(int i = 1; i <= 5; i++) {
if(i == 3) continue;
cout << i;
}

(A) 1 2 3 4 5


(B) 1 2 4 5


(C) 3 4 5


(D) 1 2



3. What is the output?
int i = 0;
while(i < 5) {
if(i == 2) break;
cout << i;
i++;
}

(A) 0 1


(B) 0 1 2


(C) 1 2 3


(D) 0



4. What happens when the following code runs?
int i = 0;
while(i < 5) {
i++;
if(i == 3) continue;
cout << i;
}

(A) 1 2 3 4 5


(B) 1 3 5


(C) 2 4


(D) 1 2 4 5



5. What will be printed?
for(int i = 1; i <= 3; i++) {
for(int j = 1; j <= 3; j++) {
if(j == 2) break;
cout << j;
}
}

(A) 121


(B) 123


(C) 111


(D) 111



6. Output of this program:
int i = 1;
while(i <= 5) {
if(i == 4) break;
cout << i;
i++;
}

(A) 1 2 3


(B) 4 5


(C) 1 2 3 4


(D) Infinite loop



7. What happens when this code runs?
int i = 0;
do {
if(i == 2) break;
cout << i;
i++;
} while(i < 5);

(A) 0 1


(B) 0 1 2


(C) 1 2 3


(D) 2 3 4



8. What is the output of this loop?
for(int i = 1; i <= 4; i++) {
if(i == 3) continue;
cout << i;
}

(A) 1 2 3 4


(B) 1 2 4


(C) 2 3 4


(D) 3 4



9. What will be printed?
int i = 1;
while(i <= 5) {
if(i == 2) {
i++;
continue;
}
cout << i;
i++;
}

(A) 1 2 3 4 5


(B) Error


(C) 1 2 4


(D) 1 3 4 5



10. What is the output?
for(int i = 1; i <= 5; i++) {
if(i == 4) return 0;
cout << i;
}

(A) 1 2 3 4 5


(B) 1 2 3


(C) Error


(D) 1 2



11. What will happen in this code?
for(int i = 1; i <= 5; i++) {
if(i == 6) return 0;
cout << i;
}

(A) 1 2 3 4 5


(B) Infinite loop


(C) No output


(D) Error



12. What is the result of this program?
int i = 1;
while(i <= 3) {
if(i == 2) goto end;
cout << i;
i++;
}
end:
cout << "Done";

(A) Done


(B) 1 2 Done


(C) 1Done


(D) Error



13. What happens here?
int x = 1;
label:
cout << x;
x++;
if(x <= 3) goto label;

(A) Infinite loop


(B) 12


(C) 1


(D) 123



14. What will the output be?
int i = 1;
while(i <= 5) {
if(i == 3) goto end;
cout << i;
i++;
}
end:
cout << "Stop";

(A) 12Stop


(B) 123Stop


(C) Stop


(D) 1Stop



15. Output of this code:
int i = 1;
do {
if(i == 2) goto label;
cout << i;
i++;
} while(i < 4);
label:
cout << "End";

(A) End


(B) 12End


(C) 1End


(D) Error



16. What is printed?
int i = 1;
do {
cout << i;
if(i == 2) break;
i++;
} while(i <= 4);

(A) Infinite loop


(B) 1 2 3 4


(C) 1 2 3


(D) 1 2



17. What will the program print?
for(int i = 1; i <= 5; i++) {
if(i == 3) continue;
if(i == 5) break;
cout << i;
}

(A) 1 2


(B) 1 2 3 4


(C) 1 2 4


(D) 1 2 4 5



18. What will be displayed?
int x = 0;
while(x < 5) {
if(x == 3) goto end;
cout << x;
x++;
}
end:
cout << "Done";

(A) 012Done


(B) 0123Done


(C) 01Done


(D) Done



19. What happens in this program?
int i = 1;
while(i <= 5) {
if(i == 3) break;
cout << i;
i++;
}
cout << i;

(A) 12


(B) 123


(C) 1234


(D) 12345



20. What will the output be?
for(int i = 1; i <= 5; i++) {
if(i == 4) break;
cout << i;
}

(A) 1 2 3


(B) 1 2


(C) 1 2 3 4


(D) 4 5



21. Output of this program:
int i = 1;
while(i <= 5) {
if(i == 2) { i++; continue; }
cout << i;
i++;
}

(A) 1 2 3 4 5


(B) 1 3 4 5


(C) 2 3 4


(D) 3 4



22. What will happen in this code?
int x = 5;
if(x > 0) return 0;
cout << "Hello";

(A) Prints Hello


(B) No output


(C) Infinite loop


(D) Error



23. What is the output?
for(int i = 1; i <= 5; i++) {
if(i == 2) goto label;
cout << i;
}
label:
cout << "End";

(A) 1End


(B) 12End


(C) 1 2 3 4 5


(D) End



24. What will the following print?
int i = 1;
label:
cout << i;
i++;
if(i <= 3) goto label;

(A) Error


(B) 1 2


(C) 1 2 3 4


(D) 1 2 3



25. Identify the output:
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
if(j == 1) continue;
cout << j;
}
}

(A) 010101


(B) 002211


(C) 020202


(D) 020202



26. What happens?
int i = 1;
do {
if(i == 3) continue;
cout << i;
i++;
} while(i <= 5);

(A) 1 2


(B) Infinite loop


(C) 1 2 4 5


(D) 1 3 5



27. What is the result?
for(int i = 1; i <= 4; i++) {
if(i == 2) continue;
if(i == 3) break;
cout << i;
}

(A) 1


(B) 1 2


(C) 1 3


(D) 1 2 3



28. What will be the output?
int i = 0;
while(i < 5) {
i++;
if(i == 4) goto end;
cout << i;
}
end:
cout << "Stop";

(A) 1 2Stop


(B) 1234Stop


(C) Stop


(D) 1 2 3Stop



29. What happens?
for(int i = 1; i <= 3; i++) {
if(i == 2) goto label;
cout << i;
}
label:
cout << "X";

(A) 1X


(B) 12X


(C) X


(D) Error



30. What will print?
int i = 1;
do {
cout << i;
if(i == 2) break;
i++;
} while(i < 4);

(A) 12


(B) 1 2 3


(C) 1 3


(D) Error



Exit mobile version