Nested Structures in C++ :

Nested Structure :

When a structure contains another structure, it is called nested structure. A structure consisting of such complex elements is called a complex structure.

Example :

  1. /* Description: store data use nested structure in C++ language */
  2. #include<iostream>
  3. using namespace std;
  4. struct name{
  5. char name[20];
  6. };
  7. struct roll{
  8. char name[20];
  9. struct name info;
  10. }data;
  11. int main()
  12. {
  13. cout<<"Enter student name: ";
  14. cin>>data.info.name;
  15. cout<<"Enter student Roll: ";
  16. cin>>data.roll;
  17. cout<<"\n\n---Data Store Completed---\n\n";
  18. cout<<"Name : "<<data.info.name <<"\nRoll: "<<data.roll;
  19. }

Output :

C++ language store data use nested structure

Arrays of Structures :

Since an array can contain similar elements, the combination having structures within an array is an array of structures. For instance, to store addresses of 100 members of the council, you need to create an array (creates 100 sets of variables).

addr mem_addr[100];

Next Update

Loading...

We adding new programming language tutorials very soon.

We make a Collaboration with HackIsOn YouTube Channel So, Please Subscribe Their Channel and keep supporting