C Structures

In C Programing Language we can use arrays when we want hold multiple element of the homogeneous data type in single variable, but what if we want to hold heterogeneous data type element, using structure you can wrap one or more variables that may be in different data types into one.


To define a structure, you use the struct keyword followed by structure name. The variables which are declared inside the structure are called as ‘members of structure’.


The student structure contains id as an positive integer, name as a string, percentage code as a float.

Declaring structure

The above example only defines an student structure without creating any structure variable. To declare a structure variable, you can do it in two ways:

Declaring structure with variables together:

Declaring the structure variable after you define the structure:

Note :– When declaring structure following points need to be keep in mind –

  • Structure is always terminated with semicolon (;).
  • Structure name as struct_name can be later used to declare structure variables of its type in a program.

Aceessing Structure Members

Member operator ‘.’ is used to access the individual structure members. It is also known as ‘dot operator’ or ‘period operator’.


Example Program: