Loading....
Coupon Accepted Successfully!

 

Nested Structures

  • A simple program can have more than one structure.
  • This method is called nested structure.
  • The structure may be simple or complex.
  • A structure consisting of complex elements are called complex structure.
  • For example

Struct stddetail

{

int id;

char name[10];

int age;

};

Struct stdmark

{

int mark1;

int mark2;

int mark3;

int mark4;

int mark5;

int total;

float average;

};

Stdmark stddet;

  • In the above example we have to structures with a single program

Accessing data from the nested structure

  • To access the data from the nested structure, is the same as the accessing data from a single structure.

  • For example

Stddet.mark1.id=100;

Program

Struct stddetail

{

int id;

char name[10];

int age;

}stddet;

Struct stdmark

{

int mark1;

int mark2;

int mark3;

int mark4;

int mark5;

int total;

float average;

} stdmark1;

void main()

{

cout<<"\n enter the student id :"<<"\n";

cin>>stddet.id;

cout<<"\n enter the student name :"<<"\n";

cin>>stddet.name;

cout<<"\n enter the student age :"<<"\n";

cin>>stddet.age;

cout<<"\n enter the student mark1 :"<<"\n";

cin>>stdmark1.mark1;

cout<<"\n enter the student mark2 :"<<"\n";

cin>>stdmark1.mark2;

cout<<"\n enter the student mark3 :"<<"\n";

cin>>stdmark1.mark3;

cout<<"\n enter the student mark4 :"<<"\n";

cin>>stdmark1.mark4;

cout<<"\n enter the student mark5 :"<<"\n";

cin>>stdmark1.mark5;

}





Test Your Skills Now!
Take a Quiz now
Reviewer Name