Trigraphs in Standard C are three-character sequences starting with two question marks that are intended to help programmers using code sets without some of the characters used by C — {}[]#|^`\~ — which are not part of the invariant subset of ISO 646. Trigraphs were a part of C++ from C++98 through C++14, but were removed from C++17.
There are 9 trigraphs in Standard C:
??=
=>#
??(
=>[
??)
=>]
??/
=>\
??<
=>{
??>
=>}
??'
=>^
??!
=>|
??-
=>~
Trigraphs are interpreted in translation phase 1, before the code is tokenized. This means that trigraphs can affect strings, character literals, and comments.
C++98 included trigraphs for compatibility with C90 and C99. Trigraphs were deprecated in C++14 and removed from C++7.
In 'Design and Evolution of C++', Stroustrup shows how Danish terminals might display a C++ program because Danish uses extra alphabetic characters in place of some ASCII characters:
int main(int argc, char* argvÆÅ)
æ
if (argc < 1 øø *argvÆ1Å=='Ø0') return 0;
printf("Hello, %søn",argvÆ1Å);
å
Encoded with trigraphs, that becomes:
int main(int argc, char* argv??(??))
??<
if (argc < 1 ??!??! *argv??(1??)=='??/0') return 0;
printf("Hello, %s??/n",argv??(1??));
??>
Written in full ASCII, the code is:
int main(int argc, char* argv[])
{
if (argc < 1 || *argv[1]=='\0') return 0;
printf("Hello, %s\n",argv[1]);
}
See also Wikipedia on Digraphs and Trigraphs.