Best operators questions in April 2012

C conditional operator ('?') with empty second parameter

16 votes

Typically the '?' operator is used in the following form:

A ? B : C

However in cases where B = A I have seen the following abbreviation

A ? : C

This surprisingly works. Is it better to leave the second parameter in (style wise), or is their a chance certain compilers won't be able to handle this?

It is not permitted by the language C (as far as I know), but compilers such as gcc have the shortcut a?:c as an extension. a?:c means the same as a?a:c.