Trigraphs in C++ with Examples
In C++, a trigraph is a three-character sequence that represents a single character. It means that trigraph sequences are the set of three characters starting from double question marks (??). These characters are constructed using a sequence of 3 characters called trigraphs and these set of the characters are replaces by a single character.
S.No. | Trigraph | Equivalent |
---|---|---|
1. | ??= | # |
2. | ??/ | \ |
3. | ??’ | ^ |
4. | ??( | [ |
5. | ??) | ] |
6. | ??! | | |
7. | ??< | { |
8. | ??> | } |
9. | ??- | ~ |
Syntax:
??=define Becomes, #define
Below is the basic implementation example of the Trigraphs sequences:
C++
// C++ implementation to // illustrate the example // of trigraph sequences # include <iostream> using namespace std; ??=define MSG "w3wiki" ??=define Program "C++" // Driver Code int main() ??< // Here ??< denotes { cout << "My message to " << MSG << endl; cout << "My program is " << Program; return 0; ??> // Here ??> denotes } |
Output:
My message to w3wiki My program is C++
Below is another example of the Trigraph sequences:
C++
// C++ program to demonstrate // the example // of trigraph sequences # include <iostream> using namespace std; // Here ??= denotes # ??=define Name "Kalpana" ??=define Age "23" ??=define Qualification "B.tech" ??=define From "Delhi" // Driver Code int main() ??< cout << "My Name is: " << Name << endl; cout << "My Age is: " << Age << endl; cout << "My Qualification is: " << Qualification << endl; cout << "I'm From " << From; return 0; ??> |
Output:
My Name is: Kalpana My Age is: 23 My Qualification is: B.tech I'm From Delhi
Contact Us