IOS define macro definition and const definition constants differ

Source: Internet
Author: User

Const

Const is a modifier in C + +. C + + is commonly used to define constants and to modify Lvalue values.

#define

The macro definition statement, which does the text substitution directly in the preprocessing phase, does not do type checking.

The biggest difference between them:

1. For a const variable, the system gives only a corresponding memory address, and # define is given an immediate number. Because the const variable is stored in a static area of memory, the const variable has only one copy while the program is running, and the macro variable defined by # define has multiple copies, so the macro consumes much more memory than the const variable during the program's run. #define所定义的宏变量在预编译的时候进行替换, the const variable determines its value at compile time. Const,enum variable into the symbol table, you can view the value of the variable in debugging. # # # no way.

2. Const checks the data for type. #define No type checking is required. Parameters () need to be defined when defining macro parameters. And the arguments in the call should not be calculated in the macro.

3. In addition to defining constants, the const has a powerful cosmetic function. #define can increase the readability of the program, and some complex functions require only one macro display.

IOS define macro definition and const definition constants differ

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.