c++ typedef 与define

c++ typedef 与define,第1张

仅用于记录学习过程

typedef 用于定义类型的别名

#define 既可用于为类型取别名,也可以定义常量等

typedef 在编译阶段有效

#define 是在预编译阶段

对指针 *** 作时:

                

typedef int * pint;
#define PINT int *
 
int i1 = 1, i2 = 2;
 
const pint p1 = &i1; //p不可更改,p指向的内容可以更改,相当于 int * const p;
const PINT p2 = &i2; //p可以更改,p指向的内容不能更改,相当于 const int *p;或 int const*p

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/707388.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-24
下一篇 2022-04-24

发表评论

登录后才能评论

评论列表(0条)

保存