Possible Duplicate:
Why would you use the ternary operator without assigning a value for the “true” condition (x = x ?: 1)
In one’s book I saw the vague (for me) syntax of ternary operator usage:
int nr = nr ? : 1; /* allowed shortcut, same as "nr ? nr : 1" */
What exactly this mean? Somewhere in the code the ‘nr’ variable is declared and it’s initial value is based on the comparison result whether the ‘nr’ (which has a junk inside it, I guess O_o) is not equal to zero… And if so then what value it would get?
This is an extension to the ternaray operator that allows the second operand to be omitted, as noted in the comment.
This:
Is equivalent to:
I believe that this is a GCC-specific extension, here’s the GCC extension page for it.
As others have pointed out in the comments, since
nris being declared and it’s value used in the declaration, the result of this line is unpredictable.