6 perverted C-language Hello World Program--Better understanding C

Source: Internet
Author: User

The following two things are mainly done in this program fragment:

1) Finish the output Hello world.

2) confusing C language code.

    #define _________}    #define ________ Putchar    #define _______ Main    #define _ (a) ________ (a);    #define ___ _______ () {    #define __ ___ _ (0x48) _ (0x65) _ (0x6c) _ (0x6c)    #define ___ _ (0x6F) _ (0x2C) _ (0x20) _ ( 0x77) _ (0x6F)    #define ____ _ (0x72) _ (0x6c) _ (0x64) _ (0x21)    #define __ ___ ____ _________    #include <stdio.h>    _____
this is mainly related to the use of a # define macro definition and the ASCII code character set.

First, let's familiarize ourselves with the specific use of the review of # define:

Macro Definition Format: #define Macro name Macro definition string

Note: the macro definition only works in the compilation preprocessing, not the true C statement line end without semicolons , and the macro name is separated from the macro definition string, so there can be no spaces in the middle of the macro definition string. Macro substitution is not valid for macro names within quotation marks.

here's how to use:

"Define symbolic Constants" #define PI 3.1415926 "facilitates program writing" #define  long_string "It is really a long longlong long STRING" printf (long_ STRING); " The nested macro definition "#define PI 3.14#define S PI*R*R" macro definition scope "macro definition can be written anywhere in the program, ranging from definition to file love endings. You can force a specified end range by #undef to "macro definition with Parameters" #define SQR (x) x*x#define SQR (x) (x) * (x)//execute procedures, replace formal parameters with arguments at compile time, and then complete the substitution with a macro definition string. If SQR (X) is a function that is generally declared, the processing of the handler waits until the program executes. Note the difference between the two, the macro definition is just a simple character substitution. When X=a+b, the two represent//a+b*a+b and (a+b) * (A+B) "macro defines the hole in the pointer type" #define POINTER int *pointer A, b; Always remember that # define is just a simple character substitution, where B is the int type. The correct method is as follows: TypeDef int * pointer;//do not omit semicolon Pointer A, B; "Compile preprocessing" #define FLAG#IF flagstatement 1#elsestatement 2#endif//statement 1 and Statement 2 only one section will be compiled into the source program "Prevent duplicate inclusion of the header file" # Ifndef function_h_included#define function_h_included#endif//function_h_included

the correspondence between the characters and the ASCII code :

0x48= ' H ' 0x65= ' e ' 0x6c= ' l ' 0x6f= ' o ' 0x2c= ', ' 0x20= ' ' 0x77= ' W 0x72= ' R ' 0x64= ' d ' 0x21= '! '

Here we look back at how to understand the first BT Hello World program.


, I've made different notation for different types of underscores, and then we can start with simple character substitution:

a macro definition string of line number 9 can be obtained by line number 11, blue can be substituted for the macro definition string of line number 6, red can be substituted with the string of row number 7, yellow can define a macro definition string of 8, the underscore 1 is replaced by}

___ _ (0x48) _ (0x65) _ (0x6c) _ (0x6c) _ (0x6F) _ (0x2C) _ (0x20) _ (0x77) _ (0x6F) _ (0x72) _ (0x6c) _ (0x64) _ (0x21)}    

Following the method shown above, all replacements are converted to

Main () {Putchar (' H ');p Utchar (' e ');p Utchar (' l ');p Utchar (' l ');p Utchar (' o ');p utchar (', ');p Utchar (');p Utchar (' W '); Putchar (' o ');p Utchar (' R ');p Utchar (' l ');p Utchar (' d ');p Utchar ('! ');}

Seemingly very confusing C code after the translation is very intuitive, although it is a simple replacement, but I think this confusion really makes C become very interesting!


Related Article

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.