C++ Decision making & Loops | Set 1
1. How many sequences of statements present in C++?
a) 4
b) 3
c) 5
d) 6
Answer: C
Explanation: There are five sequences of statements. They are Preprocessor directives, Comments, Declarations, Function Declarations, Executable statements.
2. Decision Control statements in C++ can be implemented using
a) if
b) if-else
c) Conditional Operator
d) All of the above
Answer: D
Explanation: No explanation is given for this question.
3. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
if (0) {
cout << "Hello" ;
}
else
{
cout << "Good Bye" ;
}
return 0;
}
a) Hello
b) Good Bye
c) HelloGood bye
d) Compilation Error
Answer: B
Explanation: if(0) evaluates to false condition that is why else condition is executed. In C++ programming 0 is false 1 is true.
4. if you have to make decision based on multiple choices, which of the following is best suited?
a) if
b) if-else
c) if-else-if
d) All of the above
Answer: C
Explanation: No explanation is given for this question.
5. Can we use string inside switch statement?
a) Yes
b) No
Answer: B
Explanation: No explanation is given for this question.
6. In situations where we need to execute body of the loop before testing the condition, we should use_____.
a) For loop
b) while loop
c) do-while loop
d) nested for loop
Answer: C
Explanation: No explanation is given for this question.
7. Loops in C++ Language are implemented using?
a) While loop
b) For loop
c) Do while loop
d) All of the above
Answer: D
Explanation: No explanation is given for this question.
8. While loop is faster in C++ Language, for, while or do-while?
a) For
b) while
c) do-while
d) All work ate same speed
Answer: D
Explanation: No explanation is given for this question.
9. What is the way to suddenly come out of or quit any loop in C++?
a) continue; statement
b) break; statement
c) leave; statement
d) quit; statement
Answer: B
Explanation: eg.
while(condition)
{
break;
}
10. Which of the following can replace a simple if -wlsw construct?
a) Ternary operator
b) while loop
c) do-while loop
d) fop loop
Answer: A
Explanation: No explanation is given for this question.