Friday 5 May 2017

DECLARATION OF STRUCTURES in C

To declare a structure you must start with the keyword struct followed by the structure name or structure tag and within the braces the list of the structure’s member variables. Note that the structure declaration does not actually create any variables. The syntax for the structure declaration is as follows:
struct structure-tag {
datatype variable1;
datatype variable2;
dataype variable 3;
...
};
For example, consider the student database in which each student has a roll number, name and course and the marks obtained. Hence to group this data with a structure-tag as student, we can have the declaration of structure as:
struct student {
int roll_no;
char name[20];
char course[20];
int marks_obtained ;
};
The point you need to remember is that, till this time no memory is allocated to the structure. This is only the definition of structure that tells us that there exists a user-defined data type by the name of student which is composed of the following members. Using this structure type, we have to create the structure variables:
struct student stud1, stud2 ;
At this point, we have created two instances or structure variables of the user-defined data type student. Now memory will be allocated. The amount of memory allocated will be the sum of all the data members which form part of the structure template.

Visit our site for Registration c language coaching in jaipur

0 comments:

Post a Comment