Structures in C
Structures in C
Introduction
• In C Programming, Arrays are helpful to store a group of similar data
type elements.
• But, there are some situations where we have to group non-similar
data types (int, float, char, etc.).
• To handle these type situations C programming introduced the
concept of Structures.
• Structures in C are used to group different data types to organize the
data in a structural way.
• struct keyword is used to create structures in C programming.
• For example, we are storing employee details such as name, id, age,
address, and salary.
• From the names, you can understand that they are not the same data
type.
• Normally we create a separate variable for the name, id, address,
age, and salary, but how about storing the same for 5 employees? It
will be difficult for the developer to assign the variable names to
each.
• So, We create a C structure to handle this using struct yeyword and
assign the name as an employee.
Structures in C Syntax
• The basic syntax of the C structures using struct is as shown below
struct Structure_Name
{
Data_Type Variable_Name;
Data_Type Variable_Name;
………….
};
• The struct is the system reserved keyword used to create structures
and to access structures.
• Structure_Name: Name you desire to give the structure. For ex,
employees, person, students
• Data_Type: Data type of the declared variable. For example, int, float,
char.
• Variable_Name – For example, id, name, age, salary.
struct Example