Skip to main content

Define structure; need of structures

Short answer

A structure is a user-defined data type that groups logically related variables of possibly different types under a single name. It is needed because arrays cannot hold mixed-type records; it keeps entity data together, enables whole-record assignment/parameter passing, supports arrays of records for databases, and forms the basis of linked lists, stacks, etc.

Define the structures in C programming. Explain the need of structures.

Definition

A structure is a user-defined data type in C which groups logically related variables, possibly of different data types, under a single name. Each variable inside is a member.

struct student {
    char name[30];
    int roll;
    float marks;
};
struct student s1;     /* variable */

Need of structures

  1. Arrays store only same-type data; a record (name, roll, marks) needs different types together.
  2. All data about one entity is kept together, so the program is easier to read and maintain.
  3. A whole record can be passed to or returned from a function, or assigned to another variable, in one step.
  4. An array of structures stores many records (e.g. 100 students), the basis of file records and databases.
  5. Structures are the building blocks of linked lists, stacks, queues and trees (with pointers).

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Programming chapter 8 questions →