Hello,
How can I initialize a structure if one field in the structure is itself a structure?
Thank you.
Hello,
How can I initialize a structure if one field in the structure is itself a structure?
Thank you.
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;
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 } };