answersLogoWhite

0

What are nested structures in C?

Updated: 12/16/2022
User Avatar

Wiki User

14y ago

Best Answer

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

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are nested structures in C?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are nested structures?

Nested structures means we can have a structure inside another eg: struct A { ........... ............ struct B { ........ ........ }b; }a;


Can structures be nested in c?

yes. struct a { int x; int y; } struct b{ int z; struct a w; }


Can include files be nested in c?

Yes, include files can be nested in C and C++. In fact, most library implementations do just that.


All members of nested structures must be structure variables?

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


Can you have nested header files in C?

Yes.


What is nested class in c plus plus?

s.


What is the definition of 'nested' in C programming?

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.


In C which loop is embedded within another loop?

The nested loop.


What is nesting in C programming?

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}}


Why structure variables cannot be compared?

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


Syntax of nested if in c?

If(condition) { if-else statement; } else { if-else statement; }


What is the compound in c language?

compound c language is complicated where we need to use many nested functions and loops