Difference # define, const, typedef of

一、#define

#define does not define global variables, but the macro definition. That is not the definition of variables in the true sense, but to make text replacement.

  例如:#define MAX 100

When the program is started, the first compiler code to replace all MAX 100, and then compiled. Thus available, # define not be in the compilation process, but in the pre-compilation stage.

Two, const

Const keyword is used to define constants, if a constant is const modified, then his value can not be changed. Compared with #define, const has the following advantages:

1. The pre-compiled command value just a simple replacement type checking can not be performed.

2 can be modified to protect things, to prevent accidental modification.

3. Normal compilers often not constant const allocated storage space, but stored in the symbol table, which makes it a constant during compilation, the memory does not store the read operation, so that it is more efficient.

Three, typedef

typedef action is to define a new name for a data type, data type include an internal data type (int, char, etc.) and custom data type (struct and the like). Thus, typedef is not just a simple macro substitution, and can be used at the same time declare a pointer type of multiple objects
---------------------

Author: cuchulainn_alter
Source: CSDN
original: https://blog.csdn.net/cuchulainn_alter/article/details/80260876
copyright: This article is a blogger original article, reproduced, please attach Bowen link!

Guess you like

Origin blog.csdn.net/belongHWL/article/details/91350972