Introduction to Structure

In programming, an array is used to store multiple elements of the same data type under a single name. However, if we want to store different types of data together under one name, we use a structure.A structure is a collection of heterogeneous data types, meaning it can hold variables of different types in a single unit. Each variable stored inside a structure is called a member of that structure.

In C programming, the keyword struct is used to declare a structure, and the type of a structure variable is determined by the tag name given to that structure.In simple terms, a structure allows us to group related but different types of data together in a single logical unit.

Features of Structure

  • A structure can hold elements of different data types in a single unit.
  • We can create variables of a structure type.
  • Structure members are accessed using the . (dot) operator.
  • It is possible to create an array of structures to store multiple structure variables.

To define a structure in C programming, the struct statement is used. The struct statement creates a new user-defined data type that can contain multiple members.

Declaration of Structure and Structure Variable

Declaring a structure means defining the structure’s name, specifying the data types of its members, and listing the names of the variables that will be stored inside it.

In C programming, declaring a structure is like building a box to hold related data together. This box has separate compartments for different types of data, making your code cleaner, organized, and reusable. After declaring a structure, you can create structure variables, which act as instances of this box, allowing you to store and manage data efficiently.

Example:

struct Student {
char name[50];
int age;
float marks;
};
struct Student s1, s2; // Declaring structure variables

Here, Studentis the structure, and s1 and s2 are structure variables that can hold information about individual students.

error: Content is protected !!
Scroll to Top