It is working as specified. Unfortunately, you are misusing it. You seem to expect that the condition check should produce one of two function invocations:
printf("%d",x);
printf("0");
That's now not how C works. You use the conditional expression, so the result must be a single value, which translates to a single function argument. The comma you wrote is not the comma which is used to separate arguments to functions. It is the comma operator, which is an expression itself.
The semantics of the expression "%d", x
is to evaluate "%d"
, discard the result, and then evaluate x
. x
is the result of the expression with the comma operator.
Which means your function call is equivalent to
printf(1 > 0 ? x : "0");
You pass an integer where a pointer to a string is expected. A decent compiler should flag that with a warning at least, and if yours doesn't you need to give it the proper flags to warn you about this.