typedef与#define的区别

来源:互联网 发布:组策略 windows update 编辑:程序博客网 时间:2024/06/05 19:40
#define int_ptr int *

int_ptr a, b; //相当于int *a,b;把 int * 代入,相当于int * a, b; 只是简单的宏替换;

typedef int* int_ptr;int_ptr a, b; //相当于 int *a,*b;a, b 都为指向int的指针,typedef为int* 引入了一个新的助记符;
---------------------------------------------------------
typedef int * pint ;#define PINT int *
const pint p ;//pint 是指针类型,const pint 让指针成了常量,指针不可改,指针的属性是指针地址,指针地址不可改。p不可更改,但p指向的内容可更改.
const PINT p ;//简单的宏替换,相当于const int *p,相当于const (int *p),可以说是const int ,即让*p成了常量。 p可更改,但是p指向的内容不可更改。
---------------
#define 是预处理,编译前宏替换。
typedef在编译阶段处理。微笑

0 0
原创粉丝点击