Topic 2 Array Part2
Topic 2 Array Part2
//initialize elements of
array n to 0
int n[10] = { };
//array size is omitted
array n[ ] = {0,1,2,3,4}
Initialize and Array
• Observation:
It’s possible to pass an array by values by
embedding it as a data member of a class
and passing an object of the class, which
defaults to pass – by – value.
Searching Arrays with Linear Search
• It is a 3-by – 4 array
• An array with m rows and n columns is called an m-by-n array
Multidimensional Arrays
Equivalent to:
a[ 2 ] [ 0 ] = 0;
a[ 2 ] [ 1 ] = 0;
a[ 2 ] [ 2 ] = 0;
a[ 2 ] [ 3 ] = 0;
• To get the total elements in array a:
total = 0;
for(int row = 0; row <3; ++row)
for (int column = 0; column < 4; ++column)
total += a[ row] [column];