C Pre-processor

Source: Internet
Author: User

1. #define

Using parameters in define

Note: The preprocessor does not perform calculations, only string substitution

Output

Here's the x+2, replaced and changed to X+2*X+2=14

Here the 100/square (2) is replaced and then becomes 100/2*2=100

++x*++x here the compiler multiplies x by two times

2. #运算符和 # #运算符

From the previous example, you can see that the macro in double quotes is not working, but how to include the macro parameter (#) in the string, this process is called string;

and # like, # #运算符可以用于类函数宏的替换部分

E.

Res:

3. Variable Macros: ... And _ _va_args_ _

Res:

3. #undef

Function: Cancels the definition of a given # define

#define LIMIT 400

#undef LIMIT

4. Conditional compilation

#ifdef/#ifndef #else (On Demand) #endif (must exist)

1#include <stdio.h>2 #defineJust_checking3 #defineLIMIT 44 5 intMain ()6 {7    inti;8    intTotal ;9 Ten    for(intI=1; i<=limit;i++) One   { Atotal+=2*i*i+1; - #ifdef just_checking -printf"i=%d,running total =%d \ n", total); the    #endif -    } -printf"Grand total =%d \ n", total); -    return 0; +}

5. #line and #error

#line 1000/* Current line number is 1000*/

#line "COOL.C"

6. #pragma--compiling instructions

C Pre-processor

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.