Nearby lessons
51 of 124C - Arrays
Arrays is one of the foundational topics in C programming. This lesson explains What is an Array?, Declaring an Array and Initializing an Array with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid with exam-style MCQs at the end.
What is an Array?
An array is a group of variables of the same type, stored one after another in memory, under one name. Each element is reached by its index (position), starting from 0.
Without arrays, storing 100 students' marks means 100 separate variables. With an array, it is just marks[100].
Declaring an Array
The size tells C how many elements to reserve. Remember: indexes go from 0 to size-1. So marks[5] has indexes marks[0] to marks[4].
Initializing an Array
If you give fewer values than the size, the remaining elements are filled with 0.
Program 6: Two-Dimensional Arrays (Read and Print)
A 2D array is like a table of rows and columns. Use nested loops — the outer loop for rows, the inner loop for columns.
- Array = same-type values under one name, accessed by index 0 to size-1.
- Declare: int marks[5]; Initialize: int a[3]={1,2,3};
- Use loops to read and print arrays.
- Separate programs: sum/average, max, min, linear search.
- 2D array = table; process with nested loops (rows + columns).
- Matrix addition: c[i][j] = a[i][j] + b[i][j].