关于 typedef struct 和 struct

本文详细解析了C语言中结构体的定义方法及其在实际编程中的应用,包括使用typedef和type关键字的区别,并通过实例展示了如何正确地声明和操作结构体变量。

struct{ int x; int y;}test1;

struct test{int x;int y;}test1;

typedef struct test{int x;int y}text1,text2;

type struct{int x;int y;}test1;

 
(1) struct{ int x; int y; }test1; 好,定义了 结构 test1,test1.x 和 test1.y 可以在语句里用了。
(2) struct test {int x; int y; }test1; 好,定义了 结构 test1,test1.x 和 test1.y 可以在语句里用了。与 1 比,省写 了 test
(3) typedef struct test {int x; int y; // 你漏打分号,给你添上 }text1,text2; 只说了 这种结构 的(类型)别名 叫 text1 或叫 text2真正在语句里用,还要写:text1 test1;然后好用 test1.x test1.y或写 text2 test1;然后好用 test1.x test1.y
(4)type struct {int x; int y; }test1;这个不可以。改 typedef ... 就可以了。但也同 (3)一样,还要 写:test1 my_st;才能用 my_st.x 和 my_st.y
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值