Latest Updates :

Monday, February 15, 2021

Control Statements in C++ MCQ


Control Flow Statements

1. Which of the following can replace a simple if-else construct?
(A) Ternary operator (B) while loop (C) do-while loop (D) for loop
2. Which of the following is an entry-controlled loop?
(A) do-while loop (B) while loop (C) for loop (D) Both (B) and (C)
3. Which of the following is most suitable for a menu-driven program?
(A) do-while loop (B) while loop (C) for loop (D) All of these
4. Consider the following loop :
for(int i=0; i<5; i++) ;
What will be the value of i after this loop?
(A) It will give compilation error. (B) 5 (C) 6 (D) Some Garbage value
5. A switch construct can be used with which of the following types of variable?
(A) int (B) int, char (C) int, float, char (D) Any basic datatype
6. Which of the following must be present in switch construct?
(A) Expression in ( ) after switch (B) default
(C) case followed by value (D) All of these
7. What is the effect of writing a break statement inside a loop?
(A) It cancels remaining iterations. (B) It skips a particular iteration.
(C) The program terminates immediately. (D) Loop counter is reset.
8. What is the effect of writing a continue statement inside a loop?
(A) It cancels remaining iterations.
(B) It skips execution of statements which are written below it.
(C) The program terminates immediately.
(D) Loop counter is reset.
9. If the variable count exceeds 100, a single statement that prints “Too
many” is
(A) if (count<100) cout << “Too many”;
(B) if (count>100) cout >> “Too many”;
(C) if (count>100) cout << “Too many”;
(D) None of these.
10. The break statement causes an exit
(A) from the innermost loop only. (B) only from the innermost switch.
(C) from all loops & switches. (D) from the innermost loop or switch.
11. for (; ;)
(A) means the test which is done using some expression is always true
(B) is not valid
(C) will loop forever

12. Consider the following statements:
int x = 22,y=15;
x = (x>y) ? (x+y) : (x-y);
What will be the value of x after executing these statements?
(A) 22 (B) 37 (C) 7 (D) Error. Cannot be executed

ANS: 1. A 2. D 3. A 4. B 5. B 6. A 7. A 8. B
9. C 10. D 11. C 12. B

13. Which keyword can be used for coming out of recursion?
A. break B. return C. exit D. 
Both (a) and (b)
Ans B return

14. The keyword ‘break’ cannot be simply used within:
A. do-while B. if-else C. for D. while
Ans B if-else

15. 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     
 Ans B continue

0 comments:

Post a Comment