Array of Structures
#include <stdafx.h>
#include <iostream>
#include <string>
using namespace std;
struct Student
{
int roll_no;
string name;
int mark;
}s[2]; /* Declaring a structure array of 2 elements.Each Element is itself a structure. */
int main()
{
s[0].roll_no=20;
s[0].name="ABC";
s[0].mark=98;
s[1].roll_no=30;
s[1].name="CDE";
s[1].mark=95;
cout<< "Roll number of first Student:" <<s[0].roll_no <<endl;
cout<< "Name of first Student:" <<s[0].name <<endl;
cout<< "Mark of first Student:" <<s[0].mark <<endl;
cout<< "Roll number of second Student:" <<s[1].roll_no <<endl;
cout<< "Name of second Student:" <<s[1].name <<endl;
cout<< "Mark of second Student:" <<s[1].mark <<endl;
return 0;
}
Output:
Roll number of first Student:20
Name of first Student:ABC
Mark of first Student:98
Roll number of second Student:30
Name of second Student:CDE
Mark of second Student:95