control statements exercise

C++ exercise

1. How many sequences of statements present in C++ ?

a. 5
b. 4
c. 3
d. 1

Show Answer

The correct option is (a)
Explanation:
There are five sequences of statements. They are Preprocessor directives, Comments, Declarations, Function Declarations, Executable statements.

2. Decision Control statements in C++ programming can be implemented using

a. if-else
b. if
c. Conditional Operator
d. All of the above

Show Answer

The correct option is (d)
Explanation:
No Explanation 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 Good morning” ;
}
else
{
cout << “Hello Good Evening” ;
}
return 0;
}

a. Hello Good morning
b. Hello Good Evening
c. Hello Good morning Hello Good Evening
d. Compilation Error

Show Answer

The correct option is (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. Can we use string inside switch statement ?

a. Yes
b. No

Show Answer

The correct option is (b)
Explanation:
No Explanation for this Question

5. Loops in C++ Programming are implemented using ?

a. Do while loop
b. While loop
c. For loop
d. All of the above

Show Answer

The correct option is (d)
Explanation:
No Explanation for this Question.

6. While loop is faster in C++ Language,do-while, for or while ?

a. while.
b. do-while.
c. For
d. All work with same speed

Show Answer

The correct option is (d)
Explanation:
No Explanation

7. The switch statement is also called as?

a. selective structure.
b. certain structure
c. bitwise structure
d. choosing structure

Show Answer

The correct option is (a)
Explanation:
The switch statement is used to choose the certain code to execute, So it is also called as selective structure.

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

#include < iostream >
using namespace std;
int main()
{
int n = 10;
for ( ; ; )
cout << n;
return 0;
}

a. 15.
b. 10
c. infinite times of printing n
d. none of the mentioned

Show Answer

The correct option is (c)
Explanation:
There is not a condition in the for loop, So it will loop continuously.

8. The if…else statement can be replaced by which operator?

a. Conditional operator
b. Multiplicative operator
c. Addition operator
d. Bitwise operator

Show Answer

The correct option is (a)
Explanation:
In the conditional operator, it will predicate the output using the given condition.

  • C++ Dynamic Initialization of Objects
  • C++ Copy Constructor
  • C++ Dynamic Constructor
  • C++ Destructors
  • C++ Exercise
  • C++ Operator Overloading
  • C++ Overloading Unary Operators
  • Const pointer in C
  • Void pointer in c
  • C++ Overloading Binary Operators
  • C++ Overloading Binary Operators Using Friends
  • C++ Manipulation String Using Operators
  • C++ Rules for overloading operators
  • C++ Exercise
  • C++ Basic To class Type
  • C++ Class TO Basic Type
  • C++ One class To another class type
  • C++ Exercise
  • C++ Inheritance introduction
  • C++ Single Inheritance
  • C++ Multiple Inheritance
  • C++ Ambiguity Resolution in inheritance
  • C++ Hierarchical Inheritance
  • C++ Hybrid Inheritance
  • C++ Virtual Base Classes
  • C++ Exercise
  • C++ abstract class
  • C++ nesting of classes
  • C++ Exercise
  • C++ polymorphism
  • C++ Exercise
  • C++ pointers
  • C++ Pointers TO object
  • C++ this pointer
  • C++ Pointer to Derived class
  • C++ Virtual functions
  • C++ Exercise
  • C++ streams
  • C++ unformatted I/O operations
  • C++ Put() and get()
  • C++ getline() and write()
  • C++ Formatted console I/O
  • C++ Manipulators
  • C++ Exercise
  • C++ file handling
  • C++ file stream classes
  • C++ Open and closing file
  • C++ open using constructor
  • C++ open using open()
  • C++ Detecting End of file
  • C++ File modes
  • C++ File pointers and Manipulators
  • C++ Sequential I/O
  • C++ Reading and Writing
  • C++ Updating a File
  • C++ Error handling In File
  • C++ Command Line Arguments
  • C++ Exercise
  • C++ Template introduction
  • C++ Class Templates with multiple Parameters
  • C++ Function templates
  • C++ Function templates with multiple parameters
  • C++ member function Template
  • C++ Exercise
  • C++ Exception handling
  • C++ Basics of Exception Handling
  • C++ Exception Handling Mechanism
  • C++ Throwing Mechanism
  • C++ Catch Mechanism
  • C++ Catch all Exceptions
  • C++ Re-Throwing An Exception
  • C++ Specifying Exceptions
  • C++ Exercise