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++

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ implementation to 
// illustrate the example 
// of trigraph sequences
   
# include <iostream>
using namespace std;
   
??=define MSG "GeeksforGeeks"
??=define Program "C++"
   
// Driver Code
int main()
??< // Here ??< denotes {
    cout << "My message to " << MSG << endl;
    cout << "My program is " << Program;
       
    return 0;
??> // Here ??> denotes }

chevron_right


Output:

My message to GeeksforGeeks
My program is C++

Below is another example of the Trigraph sequences:

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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;
??>

chevron_right


Output:

My Name is: Kalpana
My Age is: 23
My Qualification is: B.tech
I'm From Delhi

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.