![if !IE]> <![endif]>
The structure declared within another structure is called a nested structure. A structure ‘Student’was used to hold the student’s information in the earlier examples. Date of birth can be included in the student’s information. There are three components in the date of birth namely, date, month and year like 25-NOV-2017. Hence, another structure is used to keep the date of birth of a student. The following code creates a structure for the date of birth.
Values can be assigned to this structure as follows.
nested structures act as members of another structure and the members of the child structure can be accessed as parent structure name. Child structure name. Member name.
float height, weight;
void main( )
cout<< “ Enter the age:”<<endl;
cout<< “Enter the height:”<<endl;
cout<< “Enter the weight:”<<endl;
cout<< “The Date of birth:”<<endl;
cout<< “ Enter the day:”<<endl; cin>>mahesh.dob.date;
cout<< “Enter the month:”<<endl;
cout<< “Enter the year:”<<endl;
cout<< “The values entered for Age, height and weightare”<<endl;
cout<<mahesh.age<< “\t”<<mahesh.height<< “\t”<<mahesh.weight<<endl;
cout<< “His date of Birth is:”<<endl<<mahesh.dob.date<< “-”<<mahesh.
dob.month<< “-” <<mahesh.dob.year;
Enter the age:
Enter the height:
Enter the weight:
The Date of birth
Enter the day:
Enter the month:
Enter the year:
The values entered for Age, height and weight are
18 160.5 46.5
His date of Birth is:
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.