Hi,
I have three questions about C structures.
First,
How do I calculate the total number of members in the structure?
for example,
struct A{
int a;
int b;
}
Is it equal to sizeof(A)/sizeof(int)? But this cannot be generalized if a struct has members of different types.
How do I do this?
Second,
Is it possible to define new members to struct later after the definition, like maybe in main()?
Third,
I have tried to reintialize a struct variable using
struct A test={0,2};
Later, it is changed to test={3,5};
This gives me error saying parse error. It doesnt give any error if I explicitly intialize the individual members like test.a=3 test.b=5. Why it dint work before?
Thanks!
I have three questions about C structures.
First,
How do I calculate the total number of members in the structure?
for example,
struct A{
int a;
int b;
}
Is it equal to sizeof(A)/sizeof(int)? But this cannot be generalized if a struct has members of different types.
How do I do this?
Second,
Is it possible to define new members to struct later after the definition, like maybe in main()?
Third,
I have tried to reintialize a struct variable using
struct A test={0,2};
Later, it is changed to test={3,5};
This gives me error saying parse error. It doesnt give any error if I explicitly intialize the individual members like test.a=3 test.b=5. Why it dint work before?
Thanks!
Comment