Structure Basics
#include <stdafx.h>
#include <iostream>
#include <string>
using namespace std;
/* Structure handles a group of logically related data items with different data types. Each member has its own memory allocation. */
struct Student
{
int roll_no; /* These are the different data items of structure Student. */
string name;
int mark;
}s; /* s is the structure variable through which we can access the structure members. */
int main()
{
s.roll_no=20; /* Assigning values to the structure members with structure variable 's' using dot operator. */
s.name="ABC";
s.mark=98;
cout<< "Roll number:" <<s.roll_no <<endl; /* Accessing values of the structure members with structure variable 's' using dot operator. */
cout<< "Name:" <<s.name <<endl;
cout<< "Mark:" <<s.mark <<endl;
return 0;
}
Output:
Roll number:20
Name:ABC
Mark:98