#define
宏命令,在编译前,由预处理器做替代,如同文本编辑的替代命令,把程序中的所有遇到的词,全部替代
例如:
#define PINT int*
就是把所有的词 PINT 替换成 int * ,替换完毕再编译。 int* x; 和pint x; 的声明是等价
typedef
类型重命名,可以把一切合法的变量都定义为类型
例如:
typedef int* sint;
是语句,由编译器在编译过程中编译处理。
#include<stdio.h>
#define PINT int*
typedef int *SINT;
void main()
{
PINT a, b; / /a 为int*,b为int.
SINT x, y; / /x 为int*,y为int*.
}
#define PINT int *
typedef int *SINT;//
SINT 是类型
const SINT a,b;
const PINT x,y;
a为const int* a
b为const int* b
x为const int* x
y为const int y
SINT const a,b;
PINT const x,y;
a为const int* a
b为 const int* b
x为 int * const x
y为 int const y