Trigraphs in C++



Trigraphs in C++ are special three-character sequences that represent a certain single character, which may not be available on some keyboards or systems.

Previously, the ISO-646 character set did not have all the characters of the C syntax; therefore, some systems with their keyboard and display faced problems while dealing with those few characters.

So the trigraphs have been introduced, which start with two question marks (??) and are further followed by a third character, which the compiler considers as a particular equivalent single-character.

Trigraphs Table in C++

There are a total of nine trigraphs available in C++; here is the following table for them.

Trigraph Replaced Character Description
??= # Hash (used for directives)
??/ \ Backslash
??' ^ Caret
??( [ Left square bracket
??) ] Right square bracket
??! ` `
??< { Left curly brace
??> } Right curly brace
??- ~ Tilde

Now, the trigraphs have been officially removed from modern C++ standards (C++17, C++20 later), but they still existed in older C++ versions (C++98 / C++03, C++11, C++14).

Example

Here is the following code example for trigraph in C++ ( Note: works only in older versions of the C++ compiler).

#include <iostream>

using namespace std;

int main() {
    int arr??(3??) = {1, 2, 3};  // Equivalent to int arr[3] = {1, 2, 3};

    for (int i = 0; i < 3; i++) {
        cout << "Element " << i << ": " << arr[i] << endl;
    }

    return 0;
}

Output

Element 0: 1
Element 1: 2
Element 2: 3
Akansha Kumari
Akansha Kumari

Hi, I am Akansha, a Technical Content Engineer with a passion for simplifying complex tech concepts.

Updated on: 2025-04-22T18:50:06+05:30

320 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements