Digraph and Trigraph characters in C
Digraph Character :
The Diagraph are sequence of two character that the compiler replaces with their corresponding punctuation character.
Digraph sequence | Symbol |
<% | { left brace |
%> | } right brace |
<: | [ left bracket |
:> | ] right bracket |
%: | # hash |
which is treated the same as :-
Trigraph Character :
Trigraph are sequence of three characters (introduced by two consecutive Question marks ) that the compiler replaces with their corresponding punctuation characters.
some keywords may not have all the characters from the C character set. C supports the facility of "trigraph sequence" to print these characters. These trigraph sequences have three characters. First two are '??' and third character from C character set. some trigraph sequences are as given below -
Trigraph sequence |
Symbol |
??< |
{ left brace |
??> |
} right brace |
??( |
[ left bracket |
??) |
] right bracket |
??! |
| vertical bar |
??/ |
\ backslash |
??= |
# hash |
??- |
~ tilde |
??’ |
^ caret |
The following source line
It's saying that it will replace the trigraph sequence, but it's not.
it's print "EKD??/n"
Now understand How trigraph work in c
Trigraphs are disabled by default in gcc. If you are using gcc then compile with -trigraphs to enable trigraphs :
gcc -trigraphs source.c
The ??/ in the printf is a trigraph character which is a part of C's preprocessor.
If you enable trigraph by using gcc -trigaphs source.c , it will convert ??/ into \.your code will look like this :
which is treated the same as :-
Comments
Post a Comment