Structure:-
It is the collection of any type of data represented in a continuous memory space so that it becomes easy to use them in the programme.
Structures are also known as records.
Syntax:-
struct<structure name>
{
list of elements;
};
Example:-
struct student
{
char name[30];
int roll,marks;
};
For memory allocation to a structure, we must declare a structure variable or object argument.
struct<structure name><variable name>;
Example: struct student a;
How to initialize structure elements:
struct student a={"Kumar",101,345};
dot(.) operator:-
use to access the structure elements in a programme.
<variable/object name>.<element name>
Example:-
a.name
a.rollno
a.marks
Example:-
struct student
{
char name[30];
int roll, marks;
};
void main()
{
struct student a;
printf("enter name");
gets(a.name);
printf("enter roll no.");
scanf("%d",&a.roll);
printf("enter marks");
scanf("%d",&a.marks);
puts(a.name);
printf("%d %d",a.roll,a.marks);
}