Back To C++ Structures
nested structure means structure within a structure
//program to create a structure employee with members (rollno, name and two nested structures clas and marks ) structure clas has members (cla and section) structure marks has members physics,chemistry and marks)(example of nested structures) #include
#include
struct clas { int cla; char section; }; struct marks { int physics; int chemistry; int maths; }; struct student { int rollno; char name[20]; marks mark; clas claas; }; void main() { student st; clrscr(); cout<<"\nenter rollno of student "; cin>>st.rollno; cout<<"\nenter name of student "; cin>>st.name; cout<<"\nenter marks of student in physics "; cin>>st.mark.physics; cout<<"\nenter marks of student in chemistry "; cin>>st.mark.chemistry; cout<<"\nenter marks of student is maths "; cin>>st.mark.maths; cout<<"\nenter class of the student (1-12)"; cin>>st.claas.cla; cout<<"\nenter section of student (a,b,c,d)"; cin>>st.claas.section; cout<<"\nDisplaying the values\n"; cout<<"\nrollno of student is "<