
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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