#include using namespace std; void SetPtr(int ary[], int * & ptr); int main() { int a{100}; int * b{nullptr}; cout << "Initialization " << endl; cout << "a = " << a << endl; cout << "&a = " << &a << endl; cout << "b = " << b << endl; //cout << "*b = " << *b << endl; cout << endl << endl; b = & a; *b = -99; cout << "After b=&a; *b = -99" << endl; cout << "a = " << a << endl; cout << "&a = " << &a << endl; cout << "b = " << b << endl; cout << "*b = " << *b << endl; cout << endl << endl; int ary[10]{1,1,1,1,1,1,1,1,1,1}; b = ary; int i; cout << "setting the array " << endl; // change the values of the array. for(i = 0; i < 10; ++i) { cout << "\tAt position " << i << " A[i] = " << *b ; *b = i; cout << " but gets set to " << *b << endl; //b = ary + i * size_of(int); ++b; } cout << endl << endl; cout << "After the array is changed " << endl; // print out the array for(i = 0; i < 10; ++i) { cout << "\tary[i] = " << ary[i] << endl; } cout << endl << endl; cout << "A pass by reference" << endl; cout << "b = " << b << endl; int bry[] {9,8,7,6,5,4,3,2,1,0}; SetPtr(bry, b); cout << "After the call " << endl; cout << "bry = " << bry << endl; cout << "b = " << b << endl; cout << endl << endl; /* const int * ptr1{nullptr}; ptr1 = & a; // *ptr1 = 8; int const * ptr2{nullptr}; ptr2 = & a; // not legal, it is pointing to a non-changable item // *ptr2 = 88; int * const ptr3{&a}; *ptr3 = 99; // nope, now the ponter variable is constant. //ptr3 = nullptr */ return 0; } void SetPtr(int ary[], int * & ptr) { ptr = ary; }