What is structure in C programming?

Structure
Structure is user defined data type .It is tool by which we can store the data of different type like int ,float, char etc in single record. In array we can store only same type of data but structure encapsulates different data type variable in single record.
Syntax:
Struct [struct_type_name]
{
[type variable_name [,variable_name, …]];
[type variable_name [,variable_name, …]];
[type variable_name [,variable_name, …]];
………………………………………………….
………………………………………………….
} [structure_variable_name];
Here label which has written inside the [ ] are optional.
Example:
struct book
{
char *title;
int page;
int pub_year;
float price;
}book1,book2;

No comments: