一个结构可以包含其他结构吗?
我想做一个结构,它包含另外四个结构的数组。这个是可能的吗?代码会是什么样子的呢?
发布于 2010-05-23 02:23:11
可以,停那儿吧。例如,此结构S2包含一个由四个S1对象组成的数组:
struct S1 { int a; };
struct S2
{
S1 the_array[4];
};发布于 2010-05-23 02:22:52
当然,为什么不呢。
struct foo {
struct {
int a;
char *b;
} bar[4];
} baz;
baz.bar[1].a = 5;发布于 2010-05-23 02:23:14
是的,结构可以包含其他结构。例如:
struct sample {
int i;
char c;
};
struct b {
struct sample first;
struct sample second;
};https://stackoverflow.com/questions/2889232
复制相似问题