C++ Decision making & Loops | Set 2
11. The if...else statement can be replaced by which operator?
a) Bitwise operator
b) Conditional operator
c) Multiplicative operator
d) Addition operator
Answer: B
Explanation: In the conditional operator, it will predicate the output using the given condition.
12. The switch statement is also called as?
a) choosing structure
b) selective structure
c) certain structure
d) bitwise structure
Answer: B
Explanation: The switch statement is used to choose the certain code to execute, So it is also called as selective structure.
13. Choose a correct C++ for loop syntax.
a) for(initalization; condition; inc/dec){ // statements };
b) for(declaration; condition; incrementoperation){ // statements };
c) for(declaration; incrementoperation; condition){ // statements };
d) for(initalization; condition; incrementoperation){ // statements };
Answer: A
Explanation: increment or decrement operation at third place.
14. Choose a correct C++ do while syntax.
a) dowhile(condition){ // statements };
b) do while(condition){ // statements };
c) do{ // statements }while(condition)
d) do{ // statements }while(condition);
Answer: D
Explanation: Semicolon after while (condition) is a must.
15. Choose a correct C++ Statement.
a) a++ is (a= a+1) POST INCREMENT operator
b) a-- is (a = a-1) POST DECREMENT operator. --a is (a = a-1) PRE DECREMENT operator
c) ++a is (a = a+1) PRE INCREMENT operator
d) All of the above.
Answer: D
Explanation: No explanation is given for this question.
16. Which of the following is an entry-controlled loop?
a) For loop
b) while loop
c) do-while loop
d) both b & c
Answer: D
Explanation: No explanation is given for this question.
17. Which of the following is an exit-controlled loop?
a) While loop
b) For loop
c) Do while loop
d) both b & c
Answer: C
Explanation: No explanation is given for this question.
18. Which of the following is most suitable for a menu-dricen program?
a) For
b) while
c) do-while
d) All of the above
Answer: A
Explanation: No explanation is given for this question.
19. Consider the following loop: for(int i = 0; i<5; i++);
a) It will give compilation error.
b) 5
c) 6
d) Some Garbage value
Answer: B
Explanation: No explanation is given for this question.
20. 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
Answer: B
Explanation: No explanation is given for this question.