美文网首页
typedef和define在修饰指针变量时的区别

typedef和define在修饰指针变量时的区别

作者: Zentopia | 来源:发表于2015-09-26 17:14 被阅读194次

This is my first article written in markdown. 😉
#define PINT int *  
typedef int * pint;

Const pint p; //p的值不能改变,p指向的内存里的值可以改变。相当于int *const p,这里Const修饰的是p,pint是一个变量类型,不可拆分;  
Const PINT p; //p的值可以改变,p指向的内存里的值不能改变,相当于const int *p;或int const *p;

pint a, b; //a和b都是int类型的指针
PINT a, b; //相当于int *a, b;只有a是指针

小结:typedef声明了自定义数据类型,而define只是简单的替换。

相关文章

网友评论

      本文标题:typedef和define在修饰指针变量时的区别

      本文链接:https://www.haomeiwen.com/subject/iwrwcttx.html