C structure concept
Introduction to Structure in C
- As we know that Array is collection of the elements of same type , but many time we have to store the elements of the different data types.
- Suppose Student record is to be stored , then for storing the record we have to group together all the information such as Roll,name,Percent which may be of different data types.
- Ideally Structure is collection of different variables under single name.
- Basically Structure is for storing the complicated data.
- A structure is a convenient way of grouping several pieces of related information together.
Definition of Structure in C:
Structure is composition of the different variables of different data types , grouped under same name.
typedef struct { char name[64]; char course[128]; int age; int year; } student;
Some Important Definitions of Structures :
- Each member declared in Structure is called member.
char name[64]; char course[128]; int age; int year;
are some examples of members.
- Name given to structure is called as tag
student
- Structure member may be of different data type including user defined data-type also
typedef struct { char name[64]; char course[128]; book b1; int year; } student;
Here book is user defined data type.