Skip to study material
← Question index

QUESTION 02 · Array Basics

Define an array and explain its advantages and limitations.

5 marks

Answer in brief

An array stores several values of one element type under one name. An index identifies each element.

Example

int marks[3] = {70, 80, 90}; creates three int elements. Their names are marks[0], marks[1] and marks[2]. The number in brackets in a declaration gives the element count, not the last index. All elements belong to the same array and occupy contiguous storage.

Advantages

  1. One declaration can hold several related values.
  2. A loop can read, display or process the elements.
  3. A valid indexed element can be accessed directly without searching earlier elements.
  4. Arrays provide a convenient representation for lists, tables and matrices.

Limitations

  1. The length of an existing array object does not grow automatically.
  2. The element type is fixed by its declaration.
  3. C does not automatically check each index at runtime.
  4. Insertion or deletion in the middle of a logical list may require shifting elements.

Uses and complexity

Arrays are useful for marks, measurements and sorted lists. A direct valid element access takes O(1) time in the usual random-access model. Processing all n elements takes O(n). Storing n elements requires O(n) space, while a fixed number of counters adds O(1) auxiliary space. A single indexed access does not sort or search the whole array.

Important point

An array of length 3 has no element at index 3. Access outside its bounds has undefined behaviour; it is not guaranteed to display zero or a predictable extra value.

Diagram or flowchart

CodeBhavya illustration of array layout.
Define an array and explain its advantages and limitations. · Download diagram

Related exam questions

Related questions in the arrays category from the supplied papers. The marks below are the printed allocations, including any combined subquestion.

  • March/April 2023 · Q11(b) · 5 marks

    Write an algorithm to sum all elements in an array and find its time complexity.

    Paper P02 · page 2
  • June 2022 · Q3(a) · 7 marks

    What is an array? Describe declaration and initialisation of one- and two-dimensional arrays.

    Paper P03 · page 1

View this category in the exam question bank →