As we have seen earlier ,in C we can store similar kind of data items under a same common name in continous memory locations using arrays. But in most of the cases we need to store elements of different data types. For example if we want to store the information of student such as his name, class, roll number, we cannot store them under a single common name.

For this purpose, C allows the concept of structures. Structure can be treated as a programmer-defined data type. Arrays are built in data types. They can declared and used any time. But in case of structures, we have to design the structure with required fields and then declare variables for it.

Structure Definition: The general format of structure definition is as follows….

struct tag_name
     member 1;
     member 2;
  1. The structure definition contains the key word "struct", followed by tag name which is nothing but the structure name.
  2. Each member is declared with its own data type and name as usually. These fields are called structure members or Variables.
  3. The entire structure is terminated with a semi colon.

Note: Structures can be declared inside main( ) or outside it. Declaring the structure outside main( ) makes it global which can be used by other functions.
We declare here a structure, containing the name, class, roll number of a student.

struct student 
    char sname[20];
     int class;
     int sno;

This statement declares a new data type called ‘struct student’.
The above structure defines a student’s information which can be accessed only after declaring structure variables.

Declaring structure Variables

The structure variable declaration is similar to that of variables of any other data type.
It includes the following elements

  1. The keyword struct
  2. The structure tag name
  3. Variable name(s).
  4. Semi colon.

Suppose we declare here a employee structure and then variables for it as follows.
struct employee
Char ename[20];
int eno;            /* Structure definition */
float esal;

The structure variables can be declared as
struct employee emp; /* Declaration of structure variables*/
Therefore the general format for declaring structure variables is

struct tag_name variable_name;
The structure variables can also be declared generally as follows
struct tag_name
   Member 1;
}variable name;

The structure members themselves are not variables. They do not occupy any memory untill structure variables are declared.

Accessing Structure Members

Structure members should be linked with their respective structure variables in order to access them. This can be done with the use of a special operator ‘.’ Which is called as member operator (or) dot operator (or) period operator.
For example:

struct library
    char title[20];
    char author[20];
    int price;

Now the structure members can be accessed as follows

Once the dot operator is used the members can be treated as ordinary variables and can be read or initialized or any other operations can be performed.

scanf("%s",book1.title); scanf("%s",; scanf("%d",book1.price);

Structure variables can also be initialized as

struct health

    int weight;
    float height;


struct health student={60,180.75};

Individual members cannot be initialized inside the structure template.
Write a program to print name, address using structure.

#include< stdio.h>
#include< conio.h>
void main( )
    struct details
         char name[20];
          int hno;
          char street[20],area[20],city[20];
      clrscr( );
      printf("\nEnter name");
      printf("\n Enter house number:");
      printf("\n Enter street, area and city:");
      clrscr( ); 
      printf("\n Name : %s",;
      printf("\n House Number : %d",obj.hno);
      printf("\n Street Name : %s",obj.street);
      printf("\n  Area : %s",obj.area);
      printf("\n  City  : %s",;
    getch( );


Define a structure ABS that contains age, designation, and salary. Using this structure write a C program to read this information for one person and print it.

#include< stdio.h>
#include< conio.h>
struct ABS
  char name[20];
  int age;
  char desig[20];  /* designation */
  float salary;
void main()
    printf("\n Enter name:");
    printf("\n Enter age:");
    printf("\n Enter designation:");
    printf("\n Enter salary :");
    printf("\n Name           : %s",;
    printf("\n Age              : %d",s.age);
    printf("\n Designation : %s",s.desig);
    printf("\n Salary          : %f",s.salary);
Copyright © 2018-2020 TutorialToUs. All rights reserved.