Overview of Array in C

An Array in C programming is a fundamental derived data structure that holds a fixed-size, sequential collection of elements of the same data type under a single shared variable name. By using an array, you can store, process, and manipulate collections of hundreds of items — such as test scores, temperatures, or financial transactions — without having to declare individual variable names.

Why Do We Need Arrays in C?

Imagine writing a C program to store and calculate the average score of 100 BCA college students. Without arrays, you would need to define 100 distinct variables (s1, s2, s3, ..., s100) and write 100 separate scanf() statements. With an array, you simply declare float marks[100]; and process all records seamlessly using a 3-line for loop.

Key Characteristics of C Arrays

 Homogeneous Elements: Every element in an array must share the exact same data type (e.g., all int, all float, or all char).

 Contiguous Memory: Array elements reside in strictly adjacent, sequential memory addresses with zero gaps between elements.

 Zero-Based Indexing: The first element is always located at index 0, and the last element is at size - 1.

 Direct Random Access (O(1)): Any element can be accessed instantly using its index: array[i].

 Static Sizing: Once declared, the capacity of a standard static array cannot be expanded or contracted during execution.

Classification of Arrays in C

Arrays are categorized into several types based on their dimensional organization:

Array Classification

Syntax Declaration

Primary Use Case

One-Dimensional (1D)

int arr[10];

Linear lists, student marks, vectors, single-series sequences.

Two-Dimensional (2D)

int matrix[3][3];

Tables with rows & columns, matrices, chessboards, image grids.

Multi-Dimensional (3D+)

int space[2][3][4];

3D spatial graphics, multi-semester grade books, tensors.

Dynamic Array

int *p = malloc(n*sizeof(int));

Runtime resizable collections allocated from heap memory.

Memory Address Calculation Formulas (BCA University Favorite)

University exams frequently require students to compute the exact memory address of array elements:

1. One-Dimensional Array Address Formula

Address of arr[i] = Base Address + (i × sizeof(data_type))

2. Two-Dimensional Array (Row-Major Order in C)

C compilers store 2-D arrays row by row in memory:

Address of arr[i][j] = Base Address + [(i × Total_Columns + j) × sizeof(data_type)]

Advantages & Disadvantages of Arrays

Advantages

Disadvantages

Instant random access via index in constant O(1) time.

Fixed size — risk of running out of space or wasting memory.

Easy traversal using simple for loops.

Costly insertions and deletions (requires shifting elements).

Cache friendly due to spatial locality in RAM.

Homogeneous only — cannot store mixed data types.


Practice Session for Beginner Students

Test your conceptual knowledge of arrays with these numerical problems, MCQs, and viva questions.

Part 1: Address Calculation Numerical Problem

Problem: Given an array int arr[20]; with base address 3000 on a system where sizeof(int) = 4 bytes. What is the memory address of the 15th element (arr[14])?
Solution:
Address = Base + (index × size)
Address = 3000 + (14 × 4) = 3000 + 56 = 3056.

Part 2: Multiple Choice Questions (BCA Exam Special)

Q1. Which data structure does an array in C belong to?
A) Non-linear data structure
B) Linear data structure
C) Hierarchical data structure
D) Graph data structure
Correct Answer: B) Linear data structure.

Q2. In C, what happens if you access an array index beyond its declared bounds (e.g. arr[15] for size 10)?
A) Compiler throws an ArrayOutOfBoundsException
B) C returns 0 automatically
C) Undefined behavior (returns garbage or causes segmentation fault)
D) Automatically resizes the array
Correct Answer: C) Undefined behavior (C has no automatic bounds checking).

Q3. In which order are 2D arrays stored in C memory?
A) Column-Major Order
B) Row-Major Order
C) Diagonal Order
D) Random Order
Correct Answer: B) Row-Major Order.

Part 3: Frequently Asked University Viva Questions

1. Why does array indexing start from 0 instead of 1 in C?
Answer: The index represents an offset (distance) from the base memory address. The very first element is at distance 0 from the base address: *(arr + 0).

2. Can we change the size of an array at runtime in standard C?
Answer: No, static arrays cannot be resized. To achieve runtime resizing, you must use dynamic memory allocation functions (malloc() and realloc()).

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Stumbleupon Share on Tumblr Share on Reddit Share on Diggit

You may also like this!