Consider the following code snippet:
int i, k, m;
k = 12;
m = 34;
for (i = 0; i < 2; i++) ((i & 1) ? k : m) = 99 - i;
printf("k: %ld m: %ld\n\n", k, m);
In this stupid example, a conditional statement expression is a shortcut to:
if (i & 1) k = 99 - i; else m = 99 - i;
My compiler does not complain, and the execution of this part of the code gives the expected result
k: 98 m: 99
My question, however, is that this is valid code according to the C standard? I have never seen anything like it before.
source
share