(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
总结:
1.typedef相当于帮结构体取了个别名,用的时候还是需要初始化一个对象对来才能调用。
2.没有typedef时,如果有{}xxx;
这个xxx就是一定定义好的对象,可以直接调用。
好,定义了 结构 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
总结:
1.typedef相当于帮结构体取了个别名,用的时候还是需要初始化一个对象对来才能调用。
2.没有typedef时,如果有{}xxx;
这个xxx就是一定定义好的对象,可以直接调用。