Hurry up and look at printf (& UNIX ["\ 021% siz \ 012 \ 0"]...
Check this line of code:
Printf (& UNIX ["\ 021% siz \ 012 \ 0"], (UNIX) ["have"] + "fun"-0x60 );
See the following explanation:
First, let's look at a piece of code:
Code: |
# Include Int main () { Int A [5] = {1, 2, 3, 4, 5 }; Printf ("% d \ n", 3 [a]); Return 0; } |
In C language, array references can be in the form of 3 [A]. It is equivalent to a [3];
Let's look at the following code:
Code: |
# Include Int main () { Int A [5] = {1, 2, 3, 4, 5}, I = 4; Printf ("% d \ n", 3 [a]); Printf ("% d \ n", I [a]); Return 0; } |
This representation is also possible. In fact, it is equivalent to I [a], which is actually equivalent to a [4 ].
Let's look at the following code:
Code: |
# Include Int main () { Printf ("% d \ n", UNIX ); Return 0; } |
Why can I print it out without defining UNIX? The reason is that UNIX is defined as a macro by the compiler.
Equivalent to # define UNIX 1 printed out 1
The following describes the problem.
Code: |
# Include Int main () { Printf ("% C \ n", (UNIX) ["have"]); Return 0; } |
Here UNIX is equivalent to 1. UNIX ["have"] is equivalent to "have" [1]. We all know that "have" is a character array. then, "have" [1] is equivalent to referencing the character "have" array subscript as 1, which is actually;
Code: |
# Include Int main () { Printf ("0x % x", 'A '); Return 0; } |
The hexadecimal representation of ASC code of A is 0x61.
(UNIX) ["have"] + "fun"-0x60
It is equivalent to 0x61-0x60 + "fun", which is equivalent to 0x01 + "fun". It is equivalent to moving the character pointer back to "UN ".
The subsequent sections are explained .~
Code: |
# Include Int main () { Printf (& UNIX ["\ 021ix \ 012 \ 0"]); Return 0; } |
In the previous section, we first remove % S. % s is actually the "UN" format just mentioned.
We know that the Unix macro value is 1.
Code: |
Printf (& UNIX ["\ 021ix \ 012 \ 0"]); |
Equivalent
Code: |
Printf (& 1 ["\ 021ix \ 012 \ 0"]); |
According to the ["have"] mentioned above
Code: |
Printf (& "\ 021ix \ 012 \ 0" [1]); |
This form is used.
The difference between this reference and the above is that a character array can get a string from the element whose subscript is 1.
Restore back.
Equivalent
Code: |
Printf (& "\ 021% six \ 012 \ 0" [1], "UN "); |
That is to say, the first element is jumped over and \ 021 is jumped over.
Code: |
Printf ("% six \ 012 \ 0", "UN "); |
This is the case.
\ 012 is the carriage return in the ASC code. This string is equivalent
Code: |
Printf ("% six \ n \ 0", "UN "); |
So far this problem has been solved ..
The problem should be. printf (& UNIX ["\ 021% six \ 012 \ 0"], (UNIX) ["have"] + "fun"-0x60 );
Http://hj9707.bokee.com/4022327.html