0
What is the output of this line in C... int c = (a < b) ? b : a ;
How it will be executed??
1 Antwort
+ 2
This is called a ternary operator.
int c -> we will assign a value to c
(a < b) ? -> the question mark indicates we will assign c to a value depending on the outcome of the preceeding boolean condition (in this case a < b)
The first value after the ? is what to assign to c if the boolean condition is true. The value after the : is what to assign if the boolean condition is false.
Read ternary operators like an if-else assignment in one line. So...
int c will be the value of b if (a < b) else it will the value of a
Also the same as
int c
if(a < b)
{
c = b;
}
else
{
c = a;
}
Hope that makes sense?