Here is a listing of C++ questions on “Statements” along with answers, explanations and/or solutions:
1. How are many sequences of statements present in c++?
a) 4
b) 3
c) 5
d) 6
View Answer
Explanation: There are five sequences of statements. They are Preprocessor directives, Comments, Declarations, Function Declarations, Executable statements.
2. The if..else statement can be replaced by which operator?
a) Bitwise operator
b) Conditional operator
c) Multiplicative operator
d) Addition operator
View Answer
Explanation: In the conditional operator, it will predicate the output using the given condition.
3. The switch statement is also called as?
a) choosing structure
b) selective structure
c) certain structure
d) bitwise structure
View Answer
Explanation: The switch statement is used to choose the certain code to execute, So it is also called as selective structure.
4. The destination statement for the goto label is identified by what label?
a) $
b) @
c) *
d) :
View Answer
Explanation: : colon is used at the end of labels of goto statements.
5. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main ()
{
int n;
for (n = 5; n > 0; n--)
{
cout << n;
if (n == 3)
break;
}
return 0;
}
a) 543
b) 54
c) 5432
d) 53
View Answer
Explanation: In this program, We are printing the numbers in reverse order but by using break statement we stopped printing on 3.
Output:
$ g++ stat.cpp $ a.out 543
6. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int a = 10;
if (a < 15)
{
time:
cout << a;
goto time;
}
break;
return 0;
}
a) 1010
b) 10
c) infinitely print 10
d) compile time error
View Answer
Explanation: Because the break statement need to be presented inside a loop or a switch statement.
7. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int n = 15;
for ( ; ;)
cout << n;
return 0;
}
a) error
b) 15
c) infinite times of printing n
d) none of the mentioned
View Answer
Explanation: There is not a condition in the for loop, So it will loop continuously.
8. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int i;
for (i = 0; i < 10; i++);
{
cout << i;
}
return 0;
}
a) 0123456789
b) 10
c) 012345678910
d) compile time error
View Answer
Explanation: for loop with a semicolon is called as body less for loop. It is used only for incrementing the variable values. So in this program the value is incremented and printed as 10.
Output:
$ g++ stat2.cpp $ a.out 10
9. How many types of loops are there in C++?
a) 4
b) 2
c) 3
d) 1
View Answer
Explanation: There are 3 types of loop. They are “while loop”, “do while loop”, and, “for loop”. C++11 has introduced “for-each loop” or “range-based for loop”, but it’s ultimately a “for loop” only.
10. Which looping process is best used when the number of iterations is known?
a) for
b) while
c) do-while
d) all looping processes require that the iterations be known
View Answer
Explanation: Because in for loop we are allowed to provide starting and ending conditions of loops, hence fixing the number of iterations of loops, whereas no such things are provided by other loops.
Sanfoundry Global Education & Learning Series – C++ Programming Language.
To practice all areas of C++ language, here is complete set of 1000+ Multiple Choice Questions and Answers.
If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]
- Check Computer Science Books
- Apply for Computer Science Internship
- Check Programming Books
- Check C++ Books
- Practice Programming MCQs