|
|
楼主 |
发表于 2013-9-11 08:34:11
|
显示全部楼层
以下几种结构体定义的区别:
(1)
struct {
int x;
int y;
} test1;
(2)
struct test
{
int x;
int y;
}test1;
(3)
typedef struct test
{
int x;
int y;
} text1,text2;
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
(1) struct{ int x; int y; }test1; 定义了 结构体的对象test1, test1.x 和 test1.y 可以在语句里用了。
(2) struct test { int x; int y; }test1; 好,定义了 结构test,同时定义了结构体的对象 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 |
|