[Solved] Confusing outcome of C conditional operator [closed]


Because x is 0.

Recall that the ternary operator, if written condition ? a : b returns a if condition is true and b otherwise. You are using it with numbers, and any number except 0 is considered true as a boolean.

x ? b : c in your case is 0 ? 2 : 3, and since 0 is false, it evaluates to 3. That 3 then gets assigned to your a variable and printed – nothing unusual going on here.

solved Confusing outcome of C conditional operator [closed]