Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

What does the ??!??! operator do in C?

I saw a line of C that looked like this:
!ErrorHasOccured() ??!??! HandleError();

It compiled correctly and seems to run ok. It seems like it's checking if an error has occurred, and if it has, it handles it. But I'm not really sure what it's actually doing or how it's doing it. It does look like the programmer is trying to express their feelings about errors.

I have never seen the ??!??! before in any programming language, and I can't find documentation for it anywhere. (Google doesn't help with search terms like ??!??!). What does it do and how does the code sample work?

3 Answers

??! is a trigraph that translates to |. So it says:

!ErrorHasOccured() || HandleError();

which, due to short circuiting, is equivalent to:

if (ErrorHasOccured())
As already stated ??!??! is essentially two trigraphs (??! and ??! again) mushed together that get replaced-translated to ||, i.e the logical OR, by the preprocessor.

The following table containing every trigraph should help disambiguate alternate trigraph combinations:

Trigraph Replaces

??( [
??) ]
??< {
??> }
??/ \
??' ^
??= #
??! |
??- ~
It's a C trigraph. ??! is |, so ??!??! is the operator ||

Login / Signup to Answer the Question.