Programming in C+ A Closer Look at the Compiler float temps 5]: //this declaration allocates memory To the compiler, the value of the identifier temps alone is the base address of the array. We say temps is a pointer(because its value is an address). It "points" to a memory location 7000 7004 7008 7012 7016 100010021004100.61008 temps[o tem ps[1 tem ps[2 temps[3 temps[4] 16
16 A Closer Look at the Compiler float temps[5]; // this declaration allocates memory To the compiler, the value of the identifier temps alone is the base address of the array. We say temps is a pointer (because its value is an address). It “points” to a memory location. temps[0] temps[1] temps[2] temps[3] temps[4] 7000 7004 7008 7012 7016 100.0 100.2 100.4 100.6 100.8
Programming in C++ Out-of-Bounds Array Indexes Out-of-Bounds array indexes: an index value that in C++ is either less than 0 or greater than the array size minus 1
17 Out-of-Bounds Array Indexes Out-of-Bounds array indexes : an index value that, in C++, is either less than 0 or greater than the array size minus 1
Programming in C++ Initializing Array in a Declaration int ages[5]={40,13,20,19,36} for(int m=0; m < 5; m++ cout <<ages[ ml; 6000 6002 6004 6006 6008 40 13 20 19 36 ages[o ages[11 ages[2 ages[3 ages[4]
18 Initializing Array in a Declaration int ages[ 5 ] = { 40, 13, 20, 19, 36 } ; for ( int m = 0; m < 5; m++ ) { cout << ages[ m ] ; } ages[0] ages[1] ages[2] ages[3] ages[4] 6000 6002 6004 6006 6008 40 13 20 19 36
Programming in C++ In C++ No Aggregate Array Operations o the only thing you can do with an entire array as a whole(aggregate) with any type of component elements is to pass it as an argument to a function EXCEPTION: aggregate O is permitted for C strings (special kinds of char arrays) 19
19 In C++, No Aggregate Array Operations ❖the only thing you can do with an entire array as a whole (aggregate) with any type of component elements is to pass it as an argument to a function ❖EXCEPTION: aggregate I/O is permitted for C strings (special kinds of char arrays)
Programming in C+ Passing Arrays as Arguments in C++, arrays are always passed by reference o whenever an array is passed as an argument, its base address- the memory address of the first element of an array is sent to the called function 20
20 Passing Arrays as Arguments ❖in C++, arrays are always passed by reference ❖whenever an array is passed as an argument, its base address- the memory address of the first element of an array - is sent to the called function