I want to use a nested structure but i dont know how to enter data in it, for example:
struct A {
int data;
struct B;
};
struct B {
int number;
};
>
Each member variable of a struct generally has a name and a type. In your code, the first member of A
has type int
and name data
. The second member only has a type. You need to give it a name. Let's say b
:
struct A {
int data;
B b;
};
To do that, the compiler needs to already know what B
is, so declare that struct before you declare A
.
To access a nested member, refer to each member along the path by name, separated by .
:
A stage;
stage.b.number = 5;