printf("%d", 10 ? 0 ? 5:1:1:12) what will print
The code printf("%d", 10 ? 0 ? 5:1:1:12)
will print the value 1
. Here's an explanation of each step:
- The expression
10 ? 0 ? 5:1:1:12
is evaluated. - The ternary operator
? :
is used to evaluate the expression. It takes three operands: the condition, the value if the condition is true, and the value if the condition is false. - In this case, the condition is
10
, which is considered true because it is non-zero. - The first operand after the condition is
0 ? 5:1:1:12
. Since the condition is false (0), the value1
is chosen as the result of this operand. - Therefore, the overall expression evaluates to
1
. - The
printf
function is used to print the value1
using the format specifier%d
.
So, the output of the code will be 1
.