Arrays in C
Storing multiple values of the same type under one name.
Declaring and Using Arrays
An array holds a fixed number of elements of the same type in contiguous memory, accessed via an index starting at 0. The array's name itself acts like a pointer to its first element — this is a key C concept.
int marks[5] = {90, 85, 70, 60, 95};
printf("%d", marks[2]); // prints 70Arrays and Pointers
In C, arr[i] is actually shorthand for *(arr + i) — the array name decays to a pointer to its first element when used in most expressions. This is why arrays and pointers are so closely linked in C.
int arr[3] = {1, 2, 3};
printf("%d", *(arr + 1)); // prints 2, same as arr[1]Multi-Dimensional Arrays
A 2D array (like int grid[3][3]) is essentially an array of arrays — useful for representing tables, grids, or matrices, like a tic-tac-toe board or an image's pixel values.
🌍 Real-World Use
Student marks lists, a Sudoku or tic-tac-toe board (2D array), and image pixel data (2D/3D arrays of color values) are all real examples of arrays organizing structured data in C programs.
💡 Pro Tip
C does NOT check array bounds automatically — accessing marks[10] on a 5-element array won't necessarily crash immediately, it'll read garbage memory. This is a common source of serious bugs; always track your array size carefully.
🧪 Quick Self-Test
Check what you just learned — no pressure, just practice.
1. What is the index of the first element in a C array?
2. What does an array's name 'decay' into in most expressions?