Structures can contain other structures as members; in other words, structures can nest. Consider the following two structure types:
struct first_structure_type { int member_of_1; }; struct second_structure_type { double double_member; struct first_structure_type first_struct_member; }; The first structure type is incorporated as a member of the second structure type. You can initialize a variable of the second type as follows:
struct second_structure_type second_struct_member; second_struct_member.double_member = 12345.6789; second_struct_member.first_struct_member.integer_member_of_1 = 5; The member operator . is used to access members of structures that are themselves members of a larger structure. No parentheses are needed to force a special order of evaluation; a member operator expression is simply evaluated from left to right. In principle, structures can be nested indefinitely. Ref: http://www.crasseux.com/books/ctutorial/Nested-structures.html
yes. struct a { int x; int y; } struct b{ int z; struct a w; }
Nested structures means we can have a structure inside another eg: struct A { ........... ............ struct B { ........ ........ }b; }a;
Yes, include files can be nested in C and C++. In fact, most library implementations do just that.
I don't really get your question, so I give you an example for nested structure:struct inner1 {int i;char c;};struct outer {int i;char c;struct inner1 n1;struct {int i;char c;} n2;};valid members for a 'struct outer' type variable are:.i, .c, .n1.i, .n1.c, .n2.i, .n2.c
s.
Nested structures means we can have a structure inside another eg: struct A { ........... ............ struct B { ........ ........ }b; }a;
yes. struct a { int x; int y; } struct b{ int z; struct a w; }
Yes, include files can be nested in C and C++. In fact, most library implementations do just that.
I don't really get your question, so I give you an example for nested structure:struct inner1 {int i;char c;};struct outer {int i;char c;struct inner1 n1;struct {int i;char c;} n2;};valid members for a 'struct outer' type variable are:.i, .c, .n1.i, .n1.c, .n2.i, .n2.c
Yes.
s.
In C a structure within a structure is called nested. For example, you can embed a while loop in another while loop or for loop in a for loop or an if statement in another if statement.
The nested loop.
Nesting can be a very handy tool in C++, but should be avoided if possible.C++ gives us If statements, For loops and many other things. These can be nested. For example:A nested If statement://outer if statementIf( this is true ){//nested if statementif( this is also true ){//do something}else{//do something else}}
They can be compared with memcmp, but you should be careful if your structures contain:- pointers- alignment gaps- numeric variables (byte order!)- nested structures/unions
If(condition) { if-else statement; } else { if-else statement; }
compound c language is complicated where we need to use many nested functions and loops