Interesting things in C Language _ bt_c_code _ chaotic programming code analysis _ 1

Source: Internet
Author: User

The complexity of C language is absolutely unimaginable. For some special reasons, C exists at the same time.

Some tangled features.

The following describes some interesting C languages.Code.

Exp:

 
Main () {printf (& UNIX ["\ 021% six \ 012 \ 0"], (UNIX) ["have"] + "fun"-0x60 );}

Step 1:

For such code, the first thing to understand is to scale down, as shown below:

 
Main () {printf (& UNIX ["\ 021% six \ 012 \ 0"], (UNIX) ["have"] + "fun"-0x60 );}

As shown above, it is still hard to understand. We can scale it down:

 
Main () {printf (& UNIX ["\ 021% six \ 012 \ 0"],/
(UNIX) ["have"] + "fun"-0x60 );}

Step 2:

The scaled-down code and the function prototype of the printf function are as follows:

Size_t printf (const char * format ,...);

We know in the above Code:

Const char * format = & UNIX ["\ 021% six \ 012 \ 0"]

Our first variable parameter is:

Va_list [1] = (UNIX) ["have"] + "fun"-0x60); // simply assume that the variable parameter is an array type, participate in K & R tutorials

Next we will analyze:

Format pointer; in Unix systems, there is a default definition, that is:

# Define UNIX 1

So you can know

* Format = & UNIX ["\ 021% six \ 012 \ 0"] = & "\ 021% six \ 012 \ 0" [1]

= & ("\ 021% six \ 012 \ 0" [1]) // This indicates that the Pointer Points to this place, which is similar to & array [I]

We can see that:

* Format = "% six \ 012 \ 0" = "% six \ 021 \ 0"

Step 3:

Analysis (UNIX) ["have"] + "fun"-0x60:

(UNIX) ["have"] + "fun"-0x60 = "have" [UNIX] + "fun"-0x60

= "Have" [1] + "fun"-0x60

= 'A' + "fun"-0x60

= 97 + "fun"-0x60

= 97 + "fun"-96

= "Fun" + 1

Step 4: Merge

 
Merge the preceding * Format and... variable parameters and output them using the printf function:
 
Printf ("% six \ 021 \ 0", "fun" + 1 );

Here we use:

% S outputs "fun" + 1 as the address string, so the output is: UN

While

Output IX \ 021 \ 0 in format

Therefore, the output after merging is:

UNIX

I found that many teaching materials in China have not thoroughly explained many of the knowledge points used here, including, of course, our university

Many teachers recommended Tan's tutorials in it. In order to better understand C's suggestion, I suggest reading books written by foreigners. After all, C was invented by foreigners,

In addition, in the process of translation, it is difficult to find completely consistent Chinese characters to represent English words.

This means that English is more suitable for descriptive technology than Chinese. // If not, you can think about it.

I will not talk about it much. In view of the limited level of C language, the above analysis will inevitably lead to errors. You are welcome to bend over and look for bricks,

 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.