What is the structure?

  • 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.

In a C interview, if you’re asked “What is a structure?”, the correct answer would be:

A structure in C is a user-defined data type that allows you to group together variables of different data types under a single name. It enables you to create a composite data type that can hold related information. Structures are declared using the struct keyword, followed by a name for the structure, and then a list of member variables enclosed in curly braces.

Here’s a basic example:

c
struct Student {
int studentID;
char name[50];
float GPA;
};

In this example, Student is the structure name, and it contains three member variables: studentID of type int, name of type char array with size 50, and GPA of type float. You can then create variables of this structure type to store information about individual students.