c - Declaring inner structure variable in nested structure without referring outer structure -
i creating simple nested structure aware it's functioning process.here example:
struct employee { char ename[20]; int ssn; float salary; struct date { int date; int month; int year; }doj; }emp1;
in case if want access members of inner structure need like
emp1.doj.date = 10;
but in above structure if omit variable declaration of structure date i.e doj , try declare separately it did not require reference emp1 i.e
struct date doj;
the compiler did not give error in case. can access members of structure date without reference emp1 like
doj.date =15;
i want know how possible?
there no special scoping rules inner structures in c means scope of struct date
same scope of struct employee
. free declare objects of inner structure type anywhere can declare object of outer structure type.
for example, these declarations same yours:
struct date { int date; int month; int year; }; struct employee { char ename[20]; int ssn; float salary; struct date doj; }emp1;
Comments
Post a Comment