Download presentation
Presentation is loading. Please wait.
1
Multidimensional Arrays
December 6, 2017
2
Multidimensional Arrays
Sometimes, it is useful to have an array with more than one index. The following syntax declares an array with two indexes (the first from 0 to 29, the second from 0 to 99): char page[30][100]; The elements of this array all have two indexes: page[0][0] page[15][32] page[29][99]
3
Multidimensional Arrays
The most common number of indexes for a multidimensional array is 2. Think of it as the first index giving the row and the second the column: page[0][0] page[0][1] ... page[0][99] page[1][0] page[1][1] ... page[1][99] page[2][0] page[2][1] ... page[2][99] ... page[29][0] page[29][1] ... page[29][99]
4
Multidimensional Arrays as Parameters
Recall that when using a one-dimensional array as a function parameter, the brackets are empty: void print_array(int a[], int elements); When using a multidimensional array as a parameter, the size of every dimension after the first must be given! Generally there will also be a parameter to represent the size of the first dimension. Example: void get_page(char p[][100], int size_1);
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.