分享

关于 typedef struct 和 struct

 Jaylongor 2014-04-03


关于 typedef struct 和 struct

hchzmc  |Lv4|被浏览434次|来自问答电脑版
2013-06-26 12:57
请高手帮忙解结构体定义的区别: struct{ int x; int y; }test1; struct test {int x;
int y;
}test1; typedef struct test {int x;
int y
}text1,满意回答

检举|2013-06-26 20:51

(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

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多