Objective C Multi-dimensional arrays - Objective C

What is Multi-dimensional array in Objective-C?

The multidimensional arrays are supported by Objective-C programming language. The below statement shows the declaration of multidimensional array.

For example, the declaration of three-dimensional 5, 10, 4 integer array as follows:

Two-Dimensional Arrays

In multidimensional array the simplest form is two-dimensional array. A two-dimensional array is a list of one-dimensional arrays. The below statement explains the declaration of two dimensional arrays:

In the above statement, type is a data type of Objective-C and arrayName is an Objective-C identifier. The below table is a two dimensional array, which will have x number of rows and y number of columns. A 2-dimensional array a, which contains three rows and four columns can be shown as below:

Objective C two dimensional arrays

From the above table, Element in array “a” is identified by an element name of the form a[i] [j]. Where “a” is the name of the array, and “i” and “j” are the subscripts that uniquely identify each element in “a”.

Initializing Two-Dimensional Arrays

Multidimensional arrays are initialized by specifying bracketed values for each row. The below example is an array with 3 rows and each row has 4 columns.

The nested braces, which indicate the intended row, are optional. The below statement is equivalent to previous example:

Accessing Two-Dimensional Array Elements

The elements in two dimensional arrays are accessed by using the subscripts, i.e., row index and column index of the array.


From the above statement it will take 4th element from the 3rd row of the array.
The below example explains the using of nested loop to handle a two-dimensional array:

On compiling and executing the above code, the following result is produced:

There for the arrays can be with any number of dimensions but mostly we create one or two dimension arrays.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Objective C Topics