Informatics 2 - 7,8,9
Informatics 2 - 7,8,9
Informatics 2 - 7,8,9
Two-dimensional arrays.
Tablice dwuwymiarowe
The Agenda
1. Multidimensional arrays
2. Two-dimensional arrays
3. Initializing and displaying two-dimensional arrays
4. Examples
5. Dynamic two-dimensional arrays
6. Examples
Multidimensional arrays
Multidimensional arrays can be described as "arrays of arrays".
jimmy represents a bidimensional array of 3 per 5 elements of type int. The way
to declare this array in C++ would be:
int jimmy[3][5];
For example, the way to reference the second element vertically and fourth
horizontally in an expression would be:
jimmy[1][3];
Declares an array with a char element for each second in a century, that is more
than 3 billion chars. So this declaration would consume more than 3 gigabytes of
memory!
Two-dimensional arrays
Multidimensional arrays are just an abstraction for programmers, since we can
obtain the same results with a simple array just by putting a factor between its
indices:
int jimmy[3][5]; //is equivalent to
int jimmy[15]; //(3*5=15)
Two-dimensional arrays
0 1 2 3 4
0 e1 e2 e3 e4 e5
1 e6 e7 e8 e9 e10
Pseudo-multidimensional array
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
return 0;
}