How can开发者_如何学Python I initialize a structure if one field in the structure is itself a structure?
You need to use more braces (actually, they're optional, but GCC makes a warning these days). Here's an example:
struct s1 { int a; int b; };
struct s2 { int c; struct s1 s; };
struct s2 my_s2 = { 5, { 6, 3 } };
Nesting of structure
You can initialize a structure if one field in the structure is itself a structure
struct add{
int house;
char road;
};
struct emp{
int phone;
struct add a;
};
struct emp e = { 123456, 23, "abc"};
printf("%d %d %c",e.phone,e.a.house,e.a.road);
struct A
{
int n;
}
struct B
{
A a;
} b;
You can initialize n by the following statement. Is this what you are looking for.
b.a.n = 10;
精彩评论