Multidimentional Array

Multidimensional- Array in C

Multidimensional arrays can also be initialized. The list of initialization values is assigned to array elements in order, with the last array subscript changing first. For example:

multi-dimensonal array in c language
multi- dimensional_arrays-in-c-language-androwep
  int array[4][3] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };

Code Example


#include<stdio.h>

int main()
{
    int i, j, k, test[2][3][2];
    printf("Enter 12 values: \n");
    for(i = 0; i < 2; ++i) {
        for (j = 0; j < 3; ++j) {
            for(k = 0; k < 2; ++k ) {
                scanf("%d", &amp;test[i][j][k]);
            }
        }
    }
    // Printing values with proper index.
    printf("\nDisplaying values:\n");
    for(i = 0; i < 2; ++i) {
        for (j = 0; j < 3; ++j) {
            for(k = 0; k < 2; ++k ) {
                printf("test[%d][%d][%d] = %d\n", i, j, k, test[i][j][k]);
            }
        }
    }
    return 0;
}

Output


  Enter 12 values:
  1
  2
  3
  4
  5
  6
  7
  8
  9
  10
  11
  12

  Displaying Values:
  test[0][0][0] = 1
  test[0][0][1] = 2
  test[0][1][0] = 3
  test[0][1][1] = 4
  test[0][2][0] = 5
  test[0][2][1] = 6
  test[1][0][0] = 7
  test[1][0][1] = 8
  test[1][1][0] = 9
  test[1][1][1] = 10
  test[1][2][0] = 11
  test[1][2][1] = 12

What is multi dimensional array?

multidimensional array is an array with more than one level or dimension. For example, a 2D array, or two-dimensional array, is an array of arrays, meaning it is a matrix of rows and columns (think of a table). … Two for loops are used for the 2D array: one loop for the rows, the other for the columns.

How are multidimensional arrays useful?

Multidimensional arrays are used to store information in a matrix form — e.g. a railway timetable, schedule cannot be stroed as a single dimensional array.You may want to use a 3-D array for storing height, width and lenght of each room on each floor of a building.

What is Array give example?

Typically these elements are all of the same data type, such as an integer or string. Arrays are commonly used in computer programs to organize data so that a related set of values can be easily sorted or searched. For example, a search engine may use an array to store Web pages found in a search performed by the user.

What is called array?

In programming, a series of objects all of which are the same size and type. Each object in an array is called an array element. For example, you could have an array of integers or an array of characters or an array of anything that has a defined data type.