
































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

































struct Date
{
int day; int month; int year;
};
Date birthday = {12, 4, 1963};
struct Student { ... id; ... name; ... age; ... gender; }; student ali; ali.id = 1234;
ali.age = 19; ali.gender = 'M';
The members of a struct need not be of the same type.
What should be the types of these members?
1234 āMohammad Aliā 19 āMā
Assignment to Structure Variable
Date newBabyBirthday = today;
Student topStudent; topStudent = fred;
cout << '\n' << year; // Error!
// year is not a variable. It is only the name of // a member in a structure
// Date is not the name of a variable. It is the name of a type
cout << '\n' << today;
//cout does not know how to handle the variable
today, as it is not one of the built-in types. You
have to give it individual bits of today that it can recognize and handle
cout << today.year << today.month;
//this is OK
Accessing struct s in struct s
anOrder
123456 true 20 6 1996
note : this expression access the Date portion of the variable
Passing Structure Variables as Parameters