250+ TOP MCQs on Statements and Answers

This section on online C++ test on “Statements”. One shall practice these test questions to improve their C++ programming skills needed for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our online C++ test questions come with the detailed explanation of the answers which helps in better understanding of C++ concepts.

Here is a listing of online C++ test 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
Answer: c
Clarification: 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
Answer: b
Clarification: 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
Answer: b
Clarification: 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) :
Answer: d
Clarification: : colon is used at the end of labels of goto statements.

  250+ TOP MCQs on Template Arguments to Specify Policy Usage and Answers

5. What will be the output of the following C++ code?

  1.     #include 
  2.     using namespace std;
  3.     int main ()
  4.     {
  5.         int n;
  6.         for (n = 5; n > 0; n--)
  7.         {
  8.             cout << n;
  9.             if (n == 3)
  10.                 break;
  11.         }
  12.         return 0;
  13.     }

a) 543
b) 54
c) 5432
d) 53
Answer: a
Clarification: 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?

  1.     #include 
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int a = 10;
  6.         if (a < 15)
  7.         {
  8.             time:
  9.             cout << a;
  10.             goto time;
  11.         }
  12.         break;
  13.         return 0;
  14.     }

a) 1010
b) 10
c) infinitely print 10
d) compile time error
Answer: d
Clarification: 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?

  1.     #include 
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int n = 15;
  6.         for ( ; ;)
  7.         cout << n;
  8.         return 0;
  9.     }

a) error
b) 15
c) infinite times of printing n
d) none of the mentioned
Answer: c
Clarification: 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?

  1.     #include 
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int i;
  6.         for (i = 0; i < 10; i++);
  7.         {
  8.             cout << i;
  9.         }
  10.         return 0;
  11.     }

a) 0123456789
b) 10
c) 012345678910
d) compile time error
Answer: b
Clarification: 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
Answer: a
Clarification: There are four types of loop. They are the while, do while, nested, for the loop.

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
Answer: a
Clarification: 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.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top