Structures is a user-defined data type that allows you to hold different types of elements.
Each element of a structure is called a member.
Structures can be widely used to store various types of information such as student information,employee information,product information,etc.
A structure contains a number of data types grouped together. These data types may or may not be of the same type.
Declaring a Structure:
struct {
structure element 1 ;
structure element 2 ;
structure element 3 ;
......
......
};
Example:
struct book {
char name ;
float price ;
int pages ;
} ;
Examples:
Points to Remember:
The closing brace in the structure type declaration must be followed by a semicolon.
It is important to understand that a structure type declaration does not tell the compiler to reserve any space in memory. All a structure declaration does is, it defines the ‘form’ of the structure.
Usually structure type declaration appears at the top of the source code file, before any variables or functions are defined. In very large programs they are usually put in a separate header file, and the file is included (using the preprocessor directive #include) in whichever program we want to use this structure type.