Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print ?? and !! in different sequence will show different output

Tags:

c

trigraphs

I had found a strange output when I write the following lines in very simple way:

Code:

 printf("LOL??!\n");
 printf("LOL!!?\n");

Output: alt text

It happens even the code is compiled under both MBCS and UNICODE.

The output varies on the sequence of "?" and "!"...

Any idea?

like image 628
wengseng Avatar asked Oct 05 '10 10:10

wengseng


People also ask

How do I display output on the same line?

Print on same line with some sign between elementsThe end=”,” is used to print in the same line with a comma after each element. We can use some other sign such as '. ' or ';' inside the end parameter.

What will be the output of print () statement?

The output will be the string literal, without the quotes. If you have a set string or phrase you want to print, you can store it in a variable and pass the variable name as the argument to print() .

What is the difference between print and output in Python?

print just shows the human user a string representing what is going on inside the computer. The computer cannot make use of that printing. return is how a function gives back a value. This value is often unseen by the human user, but it can be used by the computer in further functions.


2 Answers

??! is a trigraph that gets replaced by |.

As a rule, you should never place two question mark characters together anywhere in a source file.

like image 147
James McNellis Avatar answered Oct 11 '22 14:10

James McNellis


You may try

printf( "What?\?!\n" );

In computer programming, digraphs and trigraphs are sequences of two and three characters respectively which are interpreted as one character by the programming language.

Some compilers support an option to turn recognition of trigraphs off, or disable trigraphs by default and require an option to turn them on. Some can issue warnings when they encounter trigraphs in source files. Borland supplied a separate program, the trigraph preprocessor, to be used only when trigraph processing is desired.

like image 33
stackfull Avatar answered Oct 11 '22 14:10

stackfull