Thursday, April 11, 2013

Program to use Structure to store student information


Before C++ we had a concept of structure in c language. Structure allows us to hold different types of data in one variable.
For example, if we want to store information of a student, we may have different different information, like name, address, percentage, marks etc. And we know that different fields will use different data types, name and address will need character array, percentage will need float type and marks for multiple subjects will need an integer array.

So to combine all these type of different data types at one place, concept of structure is introduced.

struct student
{
  char s_name[20];
  char s_address[50];
  int marks[5];
  float percentage;
};

We use struct  keyword to declare any structure.
And all fields declared inside structure are known as structure members.
now if we want to use these all fields for a single entity then we just need to declare a variable of this type:

struct student stud;

here, a variable stud is able hold all above mentioned information for a student-



To access members of a structure we use  (.) structure reference operator.
For detailed study about structure click here.

Run this program to understand this concept, comment below if you have any query.

0 comments:

Post a Comment

Powered by Blogger.