Python Fixed-Size Arrays & Contiguous Memory
An array is a fixed-size collection of elements of the same data type stored side-by-side in contiguous memory. You access individual items instantly in O(1) time using their zero-based index: scores[0], scores[1].
"An array is like a row of numbered lockers at the gym. Locker 0, Locker 1, Locker 2... Each locker is identical in size and sits directly adjacent to its neighbor in a continuous row."
Deep Dive: How It Works
Declaration: int scores[5]; (creates an array of 5 integers, indices 0 through 4).
Initialization: int primes[3] = {2, 3, 5}; or let C++ deduce size: int nums[] = {10, 20, 30};.
Contiguous Memory: In RAM, scores[1] is located directly after scores[0], making CPU cache access ultra-fast.
Array Length: sizeof(arr) / sizeof(arr[0]) calculates the number of elements.
Out of Bounds Danger: C++ does NOT automatically check array bounds! Accessing arr[99] on a 5-element array reads garbage memory or crashes.
Syntax Blueprint
int values[3] = {10, 20, 30};
std::cout << values[0]; // 10 (First element)
values[2] = 99; // Replaces 30 with 99Zero-indexed fixed-size collection in contiguous memory.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Accessing arr[5] on an array of size 5 (int arr[5])Why it happens: Forgetting indices run from 0 to 4.
How to fix: Valid indices for size 5 are [0], [1], [2], [3], and [4].
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Find the largest number in an array
Declare int numbers[3] = {12, 45, 29};
Find the maximum value using a loop and print "Max: 45".
Finished reading and practicing?
Mark this lesson as completed to update your course progress.