0
13kviews
Explain Single and Multidimensional array
1 Answer
0
1.1kviews

An array is a group of related data items that share a common name. For instance, we can define array name salary to represent a set of salary of a group of employees. A particular Value is indicated by writing a number called index number or subscript in brackets after the array name.

Eg: salary[10]

Single Dimensional Array

An array with a single subscript is known as one dimensional array.

Eg:

1) int number[5];

The values to array elements can be assigned as follows.

Eg: 1)

number[0] = 35; number[1] = 40; number[2] = 20; The general form of array declaration is

type variable-name[size];

The type specifies the type of element that will be contained in the array, such as int, float, or char and the size indicates the maximum number of elements that can be stored inside the array.

Eg:

1) float height[50]; 2) int group[10]; 3) char name[10];

Initialization of Arrays

The general form of initialization of arrays is:

static type array-name[size] = {list of values};

Eg:1) static int number[3] = {0,0};

If the number of values in the list is less than the number of elements, then only that many elements will be initialized. The remaining elements will be set to zero automatically.

Two-Dimensional Arrays

Two-dimensional arrays are declared as follows

type array-name[row_size][column_size];

Eg: product[i][j] = row * column;

Please log in to add an answer.