struct hello
{
char id[5];
int marks;
} a;
1) 'a' 是什么意思?请用简单的例子解释一下,我的讲师不擅长解释。
2)如果a是*a怎么办?我知道它是一个指针,但是我们什么时候使用它?
3)结构体节点是保留字吗?另外为什么我看到一些结构有这个“struct node *x”,我知道它是一个临时存储,但为什么它在单词节点旁边而不是在结构内部?就像这样:
struct node
{
*x
}
4)如果结构内部有结构怎么办?我们什么时候使用它?我可以举个例子吗?
非常感谢!
最佳答案
a
是 struct hello
的普通变量类型。
你将永远看到类似的东西
struct node
{
*x
}
在工作程序中。可能类似于struct node *x;
不过。
关于结构内的字段,它们可以像任何其他变量一样声明,因此结构内的嵌套结构可以正常工作。一个愚蠢的例子:
struct foo
{
int a;
};
struct bar
{
struct foo f;
/* If you're declaring a variable or (in this case) a structure
* member, then you don't need to give a name to the structure
*/
struct
{
int a;
} g;
};
bar
结构现在有两个字段:f
和g
。其中每一个都是另一个包含名为 a
的成员的结构。 .
可以像这样使用
struct bar bar; /* Structure names and variable names can be the same */
bar.f.a = 5;
bar.g.a = 10;
关于c - 需要解释C编程中的结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17944760/