<<< The C programming language, cont. | Index | What can we do with pointers? >>> |
There are two ways to pass a pointer to a function:
#include <iostream> using namespace std; // function gets a pointer to double void take_pointer( double * ptr ) { cout << *ptr << '\n'; } // function gets an "array" of doubles void take_fossil( double ptr[] ) { cout << ptr[ 0 ] << '\n'; } int main() { double price = 1.52; double * location = &price; take_pointer( location ); take_fossil( &price ); return 0; }
<<< The C programming language, cont. | Index | What can we do with pointers? >>> |