typedef struct结构体的用法
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了typedef struct结构体的用法,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含809字,纯文字阅读大概需要2分钟。
内容图文
typedef是类型定义的意思。typedef struct是为了使用这个结构体方便
具体区别在于:
若struct node{}这样来定义结构体的话,在定义node的结构体变量时,需要这样写:struct node n;
若用typedef,可以这样写,typedef struct node{}NODE;在申请变量时就可以这样写:NODE n;其实就相当于别名。区别就在于使用时,是否可以省去struct这个关键字。
首先:
在C中定义一个结构体类型时如果要用typedef:
typedef struct Student{
int no;
char name[12];
}Stu,student;
于是在声明变量的时候就可:Stu stu1;或者student stu2;(Stu和student同时为Student的别名)
如果没有typedef即:
struct Student{
int no;
char name[12];
}Stu;
就必须用struct Student stu1;或者struct Stu stu1;来声明
另外这里也可以不写Student(于是也不能struct Student stu1;了)
typedef struct{
int no;
char name[12];
}Stu;
其次:
在c++中如果用typedef的话,又会造成区别:
struct Student{
int no;
char name[12];
}stu1;//stu1是一个变量
typedef struct Student2{
int no;
char name[12];
}stu2;//stu2是一个结构体类型,即stu2是Student2的别名
原文:https://www.cnblogs.com/pesuedream/p/12110979.html
内容总结
以上是互联网集市为您收集整理的typedef struct结构体的用法全部内容,希望文章能够帮你解决typedef struct结构体的用法所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。