46
Question Question 40
Differentiate between one-dimensional and two-dimensional arrays.
| One-dimensional array | Two-dimensional array |
|---|---|
| One-dimensional array stores data in a single row or column. | Two-dimensional array stores data in a grid or table, with rows and columns. |
| It uses one index to access array elements. | It uses two indices to access array elements. |
For example,int arr[] = new int[10];It creates a one dimensional array arr which stores 10 elements of int type. | For example,int arr[][] = new int [3][3];It creates a two dimensional array which has three rows and three columns to store 3 x 3 = 9 elements of int type. |