C structure concept

Introduction to Structure in C

  1. 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.
  2. 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.
  3. Ideally Structure is collection of different variables under single name.
  4. Basically Structure is for storing the complicated data.
  5. 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 :

  1. Each member declared in Structure is called member.
char name[64];
char course[128];
int age;
int year;

are some examples of members.

  1. Name given to structure is called as tag
student
  1. 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.