They have a common advantage is "change the whole, to avoid the input error" What are the two different? Some.
The main difference is that the macro definition is done prior to compilation, and the const is processed during the compilation phase
Macros define constants that do not occupy memory cells and are defined by const occupy memory units
A macro definition has the same effect as a const constant-----the data is represented by a symbol, but some books say that defining an array constant cannot be used as a const, and it can be tested, and the environment is vs2015
Constant definition defines the length of an array
const int n=66;
int arr[n];
Some of the books say it's wrong, but after I test it on the vs2015, I can.
Macro definition defines the length of an array
#define N 66
int arr[n];
Macro definition with Parameters
Format:
#define the macro name (parameter list) to replace the content
#define SUM (A, b) a+v
The program code is as follows:
S=sum (6,8);
Replace A and b in the macro definition with 6 and 8, respectively, with the following code:
S=6+8;
#define没有数据类型, just a simple replacement
#include"stdafx.h"#include<stdlib.h>#defineAdd (a) (a) > (b)? (a):(B)intMain () {printf ("%s", Add ("ABC","BCD")); System ("Pause"); return 0;}
" stdafx.h " #include<stdlib.h>#define Add (a) > (b)? (a):(b)int main () { printf ("%d", add (1+2 3+4)); System ("pause"); return 0 ;}
These are all possible.
Therefore, it is generally recommended to use a function that does not recommend macro definitions
The difference between macro definition and constant definition in C language