The conditional operator is a special type of operators. It
is mainly used for making two way decision like as if – else, if the first
condition is false than else part is executed.
In other word, it first check
the condition if condition is true than the first expression or statement is
executed, when the condition is false than the second statement or expression
is executed.
Sy:
condition ? statement1 : statement2;
ex:
max = (A > B ) ? A : B;
In this example conditional operator first check the condition.
If A is greater than B than A is assigned in max i.e. max has the value of A,
other wise max has the value of B.
No comments:
Post a Comment