MENU
Question -

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 exucute 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 I executes otherwise expression 2 executes.
Example :
int y = 10, x;
x = y>10? 1:0;
cout<
Output : 0

Comment(S)

Show all Coment

Leave a Comment

Free - Previous Years Question Papers
×