CPP Conditional Operator MCQ
Cpp MCQ- Home
- Tutorials
- Cpp
- Conditional Operator
- Multiple Choice Question
(1) Which of the following operator is used to separate multiple statements in True or False case of conditional operator ?
A) ; (Semicolon)
B) : (colon)
C) , (comma)
D) . (dot)
Explanation
Multiple statements are separated by comma in ternary operator. For example if we write this statement (a < 20) ? (cout<<"True", cout<<" Here") : cout<<"False"; Then True Here will print on screen.
(2) Conditional operator can be also be used in:
A) Assignment Statement
B) Expression
C) Both A and B
D) None
Explanation
Conditional operator can also return value after condition evaluation. And this returned value can be used in assignment statement as well as in expression.
(3) Which of the following parentheses are used to execute multiple statements in True or False case of conditional operator ?
A) ( )
B) { }
C) [ ]
D) None
Explanation
Small parentheses are used in ternary operator if we want to execute multiple statements in True or False case. These statements are separated by comma.
(4) Which of the following is optional in Ternary operator statement ?
A) Condition
B) True Case
C) False Case
D) All Mandatory
Explanation
All these three parts are mandatory in syntax of ternary operator. Compiler will generate an error if we skip any one of these.
(5) Which of the following is correct syntax of conditional operator?
A) (condition) : True ? False
B) (condition) ? True : False
C) (condition) : True : False
D) (condition) ? True ? False
Explanation
In conditional operator statement first we use question mark ? after specifying condition. True and false case statements are separated by colon : symbol. Firt we write true case and then false case statements.
(6) True case in conditional operator is written after which symbol?
A) ?
B) :
C) ()
D) ;
Explanation
True case is written after the ? symbol in conditional operator. This symbol is mandatory and comes just after the condition.
(7) Conditional operator is also called _______ operator.
A) Unary
B) Binary
C) Ternary
D) None
Explanation
It is also called Ternary operator because it has three sections to execute. First condition, second TRUE section and third FALSE section.
(8) Which of the following operators are used as conditional operator ?
A) ? :
B) > >
C) : :
D) /*
Explanation
? : are used as conditional operator. ? comes after condition and : is placed after first statement.
(9) Conditional operator is good alternative of.
A) if
B) if else
C) if else if
D) nested if
Explanation
Conditional operator is good alternative of if else statement. Because it have only two possible outcomes similar to if else statement. It execute one statement when condition is TRUE and other statement when condition is FALSE.