You are on page 1of 8

A structure is a collection of variables under a single name.

These variables can be of


different types, and each has a name which is used to select it from the structure

Structure is some what similar to Array. The only different is that array is used to
store collection of similar data types while structure can store collection of any type
of data.

A structure is a user defined data type that groups logically related data items of
different data types into a single unit.

Structure is a user-defined data type in C which allows you to combine different data
types to store in a new type

Structures helps to construct complex data types in more meaningful way.


Structure is used to represent a record.

Suppose you want to store record of Student which consists of name,


address, roll number and age.

Suppose you want to store record of Book which consists of book


name, pages, price & author name.
All the elements of a structure are stored at contiguous memory locations.

A variable of structure type can store multiple data items of different data types
under the one name.

As the data of employee in company that is name, Employee ID, salary, address, phone
number is stored in structure data type.
We use ‘struct’ keyword to define a structure in C.

Syntax New Datatype name


struct structureName
{
datatype variableName1;
datatype variableName2;
. Structure
Members
.
};
Structure must end with semicolon
Suppose you want to store record of Student which consists of name,
address, roll number and age.
New Datatype name
Example
struct Student
{
char studName[15];
chat address[30];
int rollNumber;
int age;
};
Suppose you want to store record of Book which consists of book
name, pages, price & author name.
New Datatype name
Example
struct Book
{
char bookName[15];
chat author[30];
int pages;
float price;
};
Suppose you want to store record of Employee which consists of
name, ID, salary, address & dept.
New Datatype name
Example
struct Employee
{
int emp_id;
char empName[15];
chat address[30];
char dept[3]
float salary;
};

You might also like