2 answers
Best answer
Answer: a structure is a user-defined data type in C that groups together variables of different data types under one name. It is created with the keyword struct.
An array can hold only elements of the same type; a structure can hold related items of different types, such as a student's roll number (int), name (char array) and percentage (float).
struct student
{
int roll;
char name[30];
float percent;
};
struct student s1 = {1, "Asha", 87.5};
printf("%d %s %.1f", s1.roll, s1.name, s1.percent);
The variables inside are called members, and they are accessed with the dot operator, e.g. s1.roll (or with -> through a pointer to the structure). The memory occupied by a structure variable is at least the sum of the sizes of its members.
Your answer
Log in or create a free account to answer this question.