Concept:
Arrays are data structures used to store multiple values of the same data type in contiguous memory locations.
Step 1:Understanding a 1D array.
A
one-dimensional array (1D array) stores elements in a single linear sequence. Each element is accessed using one index.
Example in C++:
\[
int arr[5] = \{1,2,3,4,5\};
\]
Here each element is accessed using a single index such as arr[0], arr[1], etc.
Step 2:Understanding a 2D array.
A
two-dimensional array (2D array) stores data in a matrix-like structure consisting of rows and columns.
Example:
\[
int matrix[3][3];
\]
Elements are accessed using two indices such as:
\[
matrix[row][column]
\]
Step 3:Key difference.
The primary difference is the number of dimensions used to organize the data:
- 1D array → single dimension
- 2D array → two dimensions (rows and columns)
Conclusion:
Thus, a 2D array differs from a 1D array because it stores data in
rows and columns.