struct结构类型与typedef
来源:互联网 发布:linux下ibus 编辑:程序博客网 时间:2024/06/05 07:05
1. struct结构体定义的形式
struct{
成员表列
}变量名表列1,变量名表列2;
例如
structlist{
int a;
char c;
stuct list *next;
};(注意这个分号不能少)
这个结构体的类型名是structlist ;struct只是声明结构体需要的关键字。
如果你要定义一个结构体变量 你就可以 :结构体类型 变量名
如:struct list student;
你是不是觉得写struct list 觉得很麻烦?
那你就可以把struct list起个别名;就是绰号
可以这样
structlist{
int a;
char c;
stuct list *next;
};
typedefstruct list A;
那么你的A student; 就等同与 struct list student;
当然你也可以在声明一个结构体的时候给它起别名,也是比较常用的一种形式:
typedefstruct list{
int a;
char c;
structlist *next;
}A;
2. typedef struct和struct的区别:
typedef struct tagMyStruct
{
int iNum;
long lLength;
} MyStruct;
上面的tagMyStruct是标识符,MyStruct是变量类型(相当于(int,char等))。
这语句实际上完成两个操作:
1) 定义一个新的结构类型
struct tagMyStruct
{
int iNum;
long lLength;
};
分析:tagMyStruct称为“tag”,即“标签”,实际上是一个临时名字,不论是否有typedef struct 关键字和tagMyStruct一起,构成了这个结构类型,这个结构都存在。
我们可以用struct tagMyStruct varName来定义变量,但要注意,使用tagMyStruct varName来定义变量是不对的,因为struct 和tagMyStruct合在一起才能表示一个结构类型。
2) typedef为这个新的结构起了一个名字,叫MyStruct。
typedef struct tagMyStruct MyStruct;
因此,MyStruct实际上相当于struct tagMyStruct,我们可以使用MyStruct varName来定义变量。
如下所示:
typedef struct tagMyStruct
{
int iNum;
long lLength;
} MyStruct;
在C中,这个申明后申请结构变量的方法有两种:
(1)structtagMyStruct 变量名
(2)MyStruct 变量名
在c++中可以有
(1)structtagMyStruct 变量名
(2)MyStruct 变量名
(3)tagMyStruct变量名
- struct结构类型与typedef
- 结构标签(struct tag)与类型定义(typedef)的区别
- typedef struct与struct定义结构体
- typedef定义的struct类型与struct定义的结构体变量在使用上的区别
- typedef 与 typedef struct
- typedef与typedef struct
- typedef struct与struct
- typedef struct 与struct
- typedef struct 与 struct
- typedef struct与struct
- struct 与 typedef struct
- struct 与 typedef struct
- typedef struct与struct
- typedef struct与struct
- struct 与 typedef struct
- struct与typedef struct
- struct与typedef struct
- typedef struct与struct
- 百度员工离职总结:如何做个好员工?
- ie6不识别png图片的解决方案
- sql存储过程
- 在Windows操作系统中,如何终止占有的8080端口的tomcat进程
- POJ 1276 Cash Machine
- struct结构类型与typedef
- Hibernate事务与并发问题处理(乐观锁与悲观锁)
- IOS研究之CoreAnimation(2)-CALayer和CATransaction的详细教程
- 编译原理手记01-概要
- C语言问题总结
- 生成doc的插件asdoc
- #define dlllocal __attribute__ ((visibility ("hidden")))
- Oracle EBS R12经验谈(二)
- Eclipse安装CXF插件开发java web service 集成Spring