What is the structure in C Language?
- The structure is a user-defined data type that allows storing multiple types of data in a single unit. It occupies the sum of the memory of all members.
- The structure members can be accessed only through structure variables.
- Structure variables accessing the same structure but the memory allocated for each variable will be different.
Syntax of structure
- struct structure_name
- }[structure variables];
Let’s see a simple example.
- #include <stdio.h>
- struct student
- char name; // structure members declaration.
- int age;
- }s1; //structure variable
- int main()
- printf(“Enter the name”);
- printf(“Enter the age”);
- printf(“Name and age of a student: %s,%d”,s1.name,s1.age);
- return 0;
Enter the name shikha Enter the age 26 Name and age of a student: shikha,26