Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigraph characters

Tags:

c

trigraphs

c99 standard  5.2.1.1 Trigraph sequences

2 EXAMPLE The following source line

printf("Eh???/n");

becomes (after replacement of the trigraph sequence ??/)

printf("Eh?\n");

It's saying that it will replace the trigraph sequence, but it's not .

It's printing "Eh???/n"

Am I missing something ?

like image 325
Omkant Avatar asked Sep 17 '25 20:09

Omkant


2 Answers

Trigraphs are disabled by default in gcc. If you are using gcc then compile with -trigraphs to enable trigraphs:

gcc -trigraphs source.c
like image 92
P.P Avatar answered Sep 20 '25 12:09

P.P


The ??/ in the printf is a trigraph character which is a part of C's preprocessor.

If you enable trigraph by using gcc -trigraphs source.c, it will convert ??/ into \. Your code will look like this:

printf("Eh???/n"); // Before enable trigraph

printf("Eh?\n"); // After enable trigraph

You can visit https://en.wikipedia.org/wiki/Digraphs_and_trigraphs#C for more information.

Possible duplicate of What does the C ??!??! operator do?

like image 41
Huy Avatar answered Sep 20 '25 11:09

Huy