InterviewSolution
Saved Bookmarks
| 1. |
Explain conditional operator with suitable example? |
|
Answer» Conditional operator is also known as ternary operator because it requires three operands and can be used to replace simple if-else code. It is used to check the condition and execute first expression if condition is true else execute other. Syntax: Conditional expression? Expression 1 : Expression 2; Explanation: If the conditional expression is true then expression 1 executes otherwise expression 2 executes. Example: int y=10,x; x=y>10?1:0; cout<<x; Output: 0 |
|