---
title: "Structure versus array"
subject: "Computer Programming"
chapter: 8
key: "semester_1/computer_programming:structure-vs-array"
source: https://www.bctengineer.com/q/semester_1/computer_programming/structure-vs-array
site: BCT Engineering
---

# Structure versus array

Computer Programming · Chapter 8: Structures

- Asked in: 2072 Chaitra, 2 marks; 2073 Shrawan, 2 marks; 2069 Asar, 2 marks; 2068 Chaitra, 2 marks (asked 4 times)
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/structure-vs-array
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-8

## Question

How does a structure differ from an array? Why do we prefer structure over array?

## Short answer

A structure groups variables of different types under one name; an array holds elements of a single type. Structures are preferred when a record (e.g., student with name, roll, marks) mixes types, because they keep all fields of an entity together, allowing the whole record to be assigned, passed to functions, or returned as a unit.

## Answer

A **structure** is a user-defined type that groups variables of different types under one name. An **array** is a collection of variables of the same type.

| Basis | Structure | Array |
|---|---|---|
| Data types | Members may have different types | All elements have the same type |
| Keyword | Declared with `struct` | No keyword |
| Access | By member name: `s.roll` | By index: `a[2]` |
| Memory | Members stored in order, may have padding bytes | Elements stored in consecutive memory without gaps |
| Type | User-defined data type | Derived data type |
| Pointer to element | Arrow operator `p->x` | Pointer arithmetic `*(p+i)` |

#### Why structure is preferred over an array
A record such as a student (name, roll, marks) mixes character, integer and float data, which an array cannot hold. A structure keeps all details of one entity together under one name, so they can be copied, passed to functions and returned as a unit. An array of structures can then store many records.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is the key difference between a structure and an array?
   A. An array holds different types; a structure the same type
   B. Both hold only same-type data
   C. A structure can hold members of different types; an array holds one type
   D. A structure can hold only integers
   Answer: C. This is the basic distinction. (Key point: Data types)

2. How are array elements stored compared with structure members?
   A. Both always have padding
   B. Structure members are stored in random places
   C. Arrays have padding, structures never do
   D. Array elements are consecutive without gaps; structures may have padding bytes
   Answer: D. Padding can appear between structure members. (Key point: Memory)

3. Why is a structure preferred for a student record (name, roll, marks)?
   A. Arrays are slower
   B. Arrays cannot store numbers
   C. The record mixes char, int and float data, which an array cannot hold
   D. Structures use less memory always
   Answer: C. A single array cannot hold mixed types. (Key point: Why structure)

## Related in Computer Programming

- [Structure vs array; accessing members](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astructure-vs-array-access-members) — Computer Programming, chapter 8
- [Pass student array; display passed students](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apass-whole-array-student-info) — Computer Programming, chapter 7
- [Standard deviation and mean of array](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astandard-deviation-pseudocode) — Computer Programming, chapter 7

## Related in other subjects

- [Prefer O(n) or O(log n) algorithm](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Aprefer-on-or-ologn) — Data Structure and Algorithm, chapter 9
- [Array representation vs dynamic list](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Aarray-vs-dynamic-list) — Data Structure and Algorithm, chapter 3
- [ADT versus data structure](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Aadt-vs-data-structure) — Data Structure and Algorithm, chapter 1
- [R-2R ladder DAC versus weighted resistor](https://www.bctengineer.com/question.md?key=semester_4%2Finstrumentation_i%3Ar-2r-ladder-dac) — Instrumentation I, chapter 5
