Lesson 9.3. Multidimensional arrays

Syntax

In C, it is possible to create multidimensional arrays by specifying the size of each dimension in square brackets one after the other:

int tab[3][4];

The line above declares a table of 3 rows by 4 columns, that is 12 cells in total.

Multidimensional arrays in C

Note: theoretically, the number of dimensions is not limited. In practice, however it depends on the compiler and the available memory.

Exercise

The following multidimensional table is provided:

  char Hi[7][11] = {  {32,32, 95,32 ,32,32,32 ,95,32 ,95,32 },
                      {32,124,32,124,32,32,124,32,40 ,95,41 },
                      {32,124,32,124,95,95,124,32,124,95,32 },
                      {32,124,32,32 ,95,95,32 ,32,124,32,124},
                      {32,124,32,124,32,32,124,32,124,32,124},
                      {32,124,95,124,32,32,124,95,124,95,124},
                      {32,32 ,32,32 ,32,32,32 ,32,32 ,32,32 } };

Display each value of the table as a character respecting the layout row / columns. Here is the display of the first two lines expected:

  _    _ _ 
 | |  | (_)
 

Quiz

Which syntaxes declare an array of 5 columns by 4 rows?

Check Bravo! The first integer is the number of rows. Try again...

What is the size of the following array:

char carre[10][10];
Check Bravo! A 10x10 arrays is composed of 100 cells. Try again...

What is the size of the following array:

unsigned char image[200][300][3];
Check Bravo! This is a three-dimensional array: 200x300x3 = 180,000 cells (or bytes here). Try again...

See also


Last update : 11/24/2022