Arrays
An array is a fixed-size collection of elements of the same type stored continuously in memory.
Below is an array of size 3 (an array with 3 elements).
c is the name of the array.
To access a specific element, you must specify the index inside []. The first index is 0, and the last index is 1 less than the size.
5, 9, 7 are the values stored in the array.
5 | 9 | 7 |
c[0] | c[1] | c[2] |
Declaring Arrays, Accessing Elements, and Printing:
Multi-Dimensional Arrays
A 2D array is a 1D array of 1D arrays. You can visualize it as a table, but the elements are stored continuously, starting with the 1st row.
Passing Arrays to Functions
When you pass an array as a parameter, you are passing a pointer to the array, not the array itself. You can use [] to access elements, just like you would with a normal array. The pointer stores the address of the original array, which means you can modify the array from inside the function.