KwickAcademy C++ · 6 min · free
Arrays in C: One and Two Dimensional
An array stores values of the same type under one name, with indexes from 0 to size - 1. A 2D array uses t[row][column]; arrays pass their address to functions.
Follows the syllabus of: GSEB Std 10 Computer Studies
On screen in this lesson
What is an array?
| A group of values of the same type under one name |
| Stored side by side in memory |
| Each value is reached by an index, starting at 0 |
| The size is fixed when the array is declared |
Ways to initialise
| Code | Stores | Note |
|---|---|---|
| int a[5]; | 5 unknown values | garbage |
| int a[5] = {1, 2}; | 1 2 0 0 0 | rest become 0 |
| int a[5] = {0}; | 0 0 0 0 0 | all zeros |
| int a[] = {4,7,9}; | 4 7 9 | size becomes 3 |
Pause and predict
| int m[5]: what is m[5]? |
| Valid indexes are 0 to 4 only |
| C does not check the index for you |
| m[5] gives garbage or crashes: a bug |
Two dimensional arrays
| Rows and columns, like a class timetable |
| Declared as int t[2][3]: 2 rows, 3 columns |
| Reach an element with t[row][column] |
| Total elements = rows x columns |
Marks sheet as a 2D array
| sheet[r][c] | Maths (c=0) | Science (c=1) |
|---|---|---|
| Riya (r=0) | 78 | 88 |
| Aman (r=1) | 65 | 72 |
| Neha (r=2) | 91 | 84 |
Passing arrays to functions
| Write the parameter as int a[] and also pass the size |
| The array is not copied; its address is passed |
| So changes inside the function change the original |
| For 2D arrays give the column size: int t[][3] |
Quick answers
In int m[5], what is m[5]?
Outside the array. Valid indexes are 0 to 4.
What does int a[5] = {1, 2}; store?
1 2 0 0 0.
KwickClips from this lesson
Short clips, one idea each. Good for revision the night before.
What is the first index?43 sec
Where does i start?40 sec
Which comes first, row or column?43 sec
Is the array copied?41 secThe full lesson, in text
Hello students, welcome to Kwickprep. Your class has sixty students. Will you create sixty separate variables to store their marks? No. Today we learn arrays. We will declare and initialise them, find a total, search for a value, use two dimensional arrays, and pass arrays to functions.
An array is like a row of numbered lockers. It is a group of values of the same type, stored under one name. The values sit side by side in memory, one after another. Each value is called an element, and we reach it using its index, which is its position number starting from zero. The size of the array is fixed when you declare it, and cannot grow later.
Here we declare an array called marks that holds five ints. The values inside curly braces are its starting values, and giving them is called initialising. The first element is marks of zero, which is seventy two. The last element is marks of four, which is fifty eight. Notice that a size five array has indexes zero to four.
There are four common ways to start an array. If you give no values, a local array holds garbage, meaning unknown leftover values. If you give fewer values than the size, the remaining elements become zero. So equals curly zero is a quick way to fill every element with zero. And if you leave the size empty, C counts the values and sets the size for you, here three.
Pause and predict. In an array m of size five, what is m of five? The valid indexes are only zero to four, so m of five is outside the array. C does not check this for you, and there is no error message. The program may print garbage or crash, so always keep the index less than the size.
Traversal means visiting every element once, and a for loop is perfect for it. The loop variable i goes from zero to four, which are exactly the valid indexes. Each time, sum plus equals m of i adds that element to sum. The marks add up to three hundred sixty nine, so it prints Total three hundred sixty nine.
Now let us search for the mark ninety. Linear search checks elements one by one from the start. When m of i double equals ninety, break stops the loop at once. Ninety is at index three, so it prints Found at three. If ninety were not in the array, the loop would finish and i would be five, which tells us, not found.
Some data comes in rows and columns, like a class timetable or a marks sheet. For this, C has two dimensional arrays. Int t, two, three means two rows and three columns. You reach one element by giving the row index and then the column index. The total number of elements is rows into columns, so here six.
Each inner pair of curly braces fills one row. We use nested loops, the outer loop r for rows and the inner loop c for columns. For each row, the inner loop prints three values. Then backslash n moves to a new line. So we see one two three, and then four five six. Remember that t of one comma two, written with two square brackets, is six.
Here is a marks sheet declared as int sheet, three, two, which means three rows and two columns. Row zero is Riya, with seventy eight in maths and eighty eight in science. Row one is Aman, with sixty five and seventy two. Row two is Neha, so sheet of two, zero is ninety one, her maths mark.
Now let us pass arrays to functions. The parameter is written as int a with empty square brackets, and we pass the size as a second parameter. The whole array is not copied, only the address of its first element is passed. So if the function changes an element, the original array in main changes too. For a two dimensional array, you must give the column size, like int t, empty brackets, three.
Here the function total receives the array as a, and its size as n. Inside, the loop adds every element to s and returns it. In main, we pass only the name m, without square brackets, and the size three. Forty plus thirty five plus twenty five is one hundred.
Now a function that gives five bonus marks. Bonus adds five to every element of a. Because the address was passed, a and m are the same array in memory. So after the call, main prints sixty five and seventy five. Unlike normal variables, arrays behave like call by reference.
Let us revise what we learned today. An array stores values of the same type under one name. Indexes start at zero, so an array of size n uses zero to n minus one. A for loop helps us traverse, add and search an array. A two dimensional array uses a row index and a column index. And when you pass an array to a function, its address goes, so changes are kept. Now try finding the highest mark in an array yourself.
Courses that teach this
| Course | Unit |
|---|---|
| GSEB Std 10 Computer Studies | Programming Fundamentals & C Language |
| Programming All levels C | Arrays and Strings |
Voice-over in this lesson is AI-generated. The script is written and checked by Kajal Ma'am. Boards can revise a syllabus mid-year, so confirm anything you plan around against the official board circular. Keep your passwords, OTPs and ID numbers to yourself — we never ask for them. To reach Kajal Ma'am, use the WhatsApp button; sharing your number there is how we call you back.
Free to watch, no sign-up. Live classes with Kajal Ma'am are the paid course; these lessons stay free either way.

