C – Structures

Introduction:

  • Applications are used to store and process the information
  • We store information using variables and process using functions.
  • We use different types of variables to store the information as follows.

Primitive variable: stores only one value at a time.

  • int a = 10;

Array variable: stores more than one value but of same type.

  • int arr[5] = {10, 20, 30, 40, 50};

Structure variable: stores more than one value of different data types. We define structures using struct keyword.

struct Employee
{
            int id;
            char name[20];
            float salary;
};
struct Employee e = {101, “Amar”, 35000};

Array of Structures: used to store more than one record details.

struct Employee{
            int id;
            char name[20];
            float salary;
};
struct Employee arr[3];

Memory representation:

Note: Structure is a data type and memory allocate to structure only when we create variable

Structure (Data type)Memory allocation (create variable)
struct Employee
{
            int id;
            char name[20];
            float salary;
};
struct Employee e;
Scroll to Top