A function update_pointer takes a format argument called p of type int* and must change the value of this argument. Provide two possible ways in which the function may be defined. For each way, show the header of the function and how it should be invoked to change the value of
an actual argument called ptr.
ok, so my answer is this:
1)
1 2 3
void update_pointer(int *&p); // header declaration
update_pointer(p) // to invoke the function.
#include <iostream>
usingnamespace std;
void update_int1(int & int_ref) { int_ref=5; }
void update_int2(int * int_ptr) { *int_ptr=10; }
void update_int_ptr1(int * & int_ptr_ref) { int_ptr_ref=(int*)0xff; }
void update_int_ptr2( /*...*/ ) { /*...*/ }
int main()
{
int n=0;
int * p=(int*)0x11;
cout << "n=" << n << endl;
//update a number using a reference
update_int1(n);
cout << "n=" << n << endl;
//update a number using a pointer
update_int2(&n);
cout << "n=" << n << endl;
cout << "p=" << p << endl;
//update a pointer using a reference
update_int_ptr1(p);
cout << "p=" << p << endl;
//update a pointer using a ...
//...
return 0;
}