L32-L33-Array of Structures
L32-L33-Array of Structures
Structures: overview
▪ Definition & structure ▪ Giving values to members
variable declaration Using dot operator ‘.’
struct student s1. rollno = 25;
{ int rollno; cin>>s1.name;
int age;
char name[20]; ‘.’ operator acts as Link between
}s1, s2, s3; member and a Structure variable.
• Array of structures
0 1 2 … 98 99
0 1 2 … 98 99
student[1].subject1 43
main(){ student[1].subject2 44
marks student[]={
student[1].subject3 45
{45,47,49},
student[2].subject1 46
{43,44,45},
student[2].subject2 42
{46,42,43}
}; student[2].subject3 43
student[1].subject[2];
▪ Refers to the marks obtained in the third subject by the second student.
for(i=0;i<=2;i++)
printf("\nTotal of student[%d]= %d", i, student[i].total);
return 0;
}
Write programs to
1. Create a student record with name, rollno, marks of 3 subjects (m1, m2, m3).
Compute the average of marks for 3 students and display the names of the
students in ascending order of their average marks.
This statement declares product as an array of 2 elements, each of the type struct
inventory.
ptr=product; assigns the address of the zeroth element of product to ptr or ptr
points to product[0];
When ptr is incremented by one, it points to the next record. i.e. product[1]
ptr=prod;
• Array of Structures