Re: ternary operator?
This conditional operator is a little stranged and it's the only one operator with operate three expresions.
Ternary operator is used to substitute code below for example:
int max, a, b;
if (a > b) // if condition is true do it
{
max = a;
}
else // if condition is false
{
max = b;
}
with ternary
max = (a > b) ? a : b;
in this case if a > b are true then max = a, if not max = b
it has the format:
exp1 ? exp2 : exp3;
if exp1 is true the result is exp2, if false the result is exp3
= is used to attribute values
== is used to compare
leomecma