Question: Consider a situation where we'd like to pass a pointer to a function, have the pointer point to something else, and have that assignment reflected

Consider a situation where we'd like to pass a pointer to a function, have the pointer point to something else, and have that assignment reflected in the caller. To accomplish just that, we can pass a pointer by reference to a function! Given the following declaration:
void MyFunction(int*& param);
what is the type of MyFunction's parameter param?
Hint: the declarator operators in the declaration int*& param bind to the type with left-to-right associativity. Expanding out from the type, we see int followed by *. At this point, we have an int* aka a pointer to an int object. Subsequently, we observe the &,(int*)&. Therefore, we can read this declaration from right-to-left: param is a reference to a pointer to an integer object.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!