typedef

typedef语法规则其实简单来说定义对象语法前加关键字typedef剩下原本定义对象标识符换成类型标识符对应语义从定义对象改成定义类型别名typedef看起来复杂根本原因对象定义语法比较复杂分隔符*和[]用法
typedef struct node{
datatype data;
struct node *lchild,*rchild;
}bintnode;
对应对象定义:
struct node{
datatype data;
struct node *lchild,*rchild;
}bintnode;
去除bintnode来看类型struct node完整描述加上了bintnode来看表示定义了struct node类型对象bintnode前面有typedef因此bintnode对象名而类型名定义了类型别名bitnode实际上指struct node完整类型
typedef定义类型别名作用域内和被定义原类型语义上等价表示同类型名称里typedef之bitnode和struct node互相代替(注意C++命名空间类型名和对象名没有重复struct省略struct node等价于node)
更复杂:
struct node{
datatype data;
struct node *lchild,*rchild;
}bintnode, *bintree;
注意定义对象时*修饰对象本身而修饰类型因此里定义了struct node对象bintnode和struct node*类型对象bintree
对应类型定义:
struct node{
datatype data;
struct node *lchild,*rchild;
}bintnode, *bintree;
里定义了类型别名bintnode表示完整类型struct node及bintree表示类型struct node*
拆开来成了
typedef struct node{
datatype data;
struct node *lchild,*rchild;
}bintnode;

typedef bintnode *bintree;
种写法看起来应该稍微清楚了
至于下面cirqueue和上面bintnode类似里省略了结构体名称匿名类型样写主要好处类型名省略struct(C++里面样写也省略)
====
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值