1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#include <iostream>
double stdDev( const double* const pointers[], int size ) ;
int main()
{
const int N = 6 ;
double v[N] = { 46.1, 47.2, 48.3, 49.4, 50.5, 51.6 }; // array of values
double* array_of_pointers[N] = { v, v+1, v+2, v+3, v+4, v+5 } ; // array of pointers to values
// pass the array of pointers to the function
const double sigma = stdDev( array_of_pointers, N ) ;
// use the value returned by the function
}
double stdDev( const double* const pointers[], int size )
{
double result = 0 ;
// to verify that we can access the elements of the array
// that was passed, print out the contents of the array
for( int i = 0 ; i < size ; ++i )
{
const double* ptr = pointers[i] ; // get the pointer
if( ptr != nullptr ) // if the pointer is not null
{
double value = *ptr ; // get the value pointed to
std::cout << value << ' ' ; // print it put
}
else // pointer is null
std::cout << "nothing " ; // there is no value
}
std::cout << '\n' ;
// compute result
return result ;
}
|