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