A structure is a user-defined data type in C that allows related variables of different data types to be grouped together under one name.
A structure is a user-defined data type in C that allows related variables of different data types to be grouped together under one name.
A student record may contain a roll number, name and percentage.
These different values can be grouped into one structure called
Student.
Structures are used when different pieces of related information need to be treated as one logical record. They make related data easier to organize and manage.
A student has a roll number (int), percentage (float), and grade (char). A structure can store all three as one student record.
Here, Student is the structure name and
rollNo, percentage and
grade are its members.
The variables declared inside a structure are called structure members. Different members can have different data types.
Here, rollNo, percentage and
grade are structure members.
After defining a structure, a variable of that structure type can be declared to store a record.
Here, s1 is a structure variable of type
struct Student.
The dot operator (.) is used to access the members of a structure variable.
Here, the dot operator is used to access the
rollNo and percentage members of
the structure variable s1.
A structure variable can be initialized when it is declared by providing values for its members in the same order in which they are declared.
The values are assigned to rollNo,
percentage and grade, respectively.
Roll Number = 101
Percentage = 82.5
Write a C program to define a structure named
Student, accept a student's roll number and percentage,
and display the stored information.
Create a Student structure with
rollNo and percentage members.
Use the dot operator to access them.
A structure groups related data under one name. After declaring a structure variable, its individual members can be accessed using the dot operator.
Enter roll number: 101
Enter percentage: 82.5
Roll Number = 101
Percentage = 82.5
A structure is useful for representing a complete record containing related values of different data types. The dot operator is used to access individual members of a structure variable.
| Concept | Remember |
|---|---|
| Structure | User-defined data type that groups related variables. |
| Member | Variable declared inside a structure. |
| Structure Variable | Variable used to store a structure record. |
| Dot Operator (.) | Used to access structure members. |
Watch a beginner-friendly explanation of structures in C.
A short handwritten-style revision sheet for structures will be provided here.
Use the mind map for quick revision of structure definition, members, variables and member access.