Structures
 
Introduction
 
The C language allows us to create custom data types.
 
The structure is a custom data type which c combines different data types .
 
The structure is a custom data type which combine different data types to form a new user define data type.
 
Definition
 
A structure is a collection of variable reference under one name providing a convincible means of related information together.
 
Format: struct tag_name
{
data _type member1;
data_type member2;
-------------------
---------------------
};
 
here a keyboard struct declares a structes to hold the details of field of different data types.
 
Example:
struct addr
{
char name [30];
char city [15];
int pincode ;
};
 
Creating Structure variable
 
structure can be created in two ways:
 
1. declaration using tagname anywhere in the program.
 
Example:
 
struct book
{
char name [30];
char author [25];
float price;
};
struct book book1 book2
 
2. it is also allowed to combine structure declaration and variable declaration in one statement.
 
Example:
 
struct person
{
char *name;
int age;
char*address;
};
p1,p2,p3
 
while declaring structure variable along with their definition, the use of tag-name is optional.
 
Struct
{
char *name;
int age;
char * address;
}
p1,p2,p3
 
Image showing how the given value allocate in structure with the help of an example >