void foo(int*& f)
here the argument is a non-constant reference to the pointer, so you can perform actions on the pointer in the function body, and then the changes will occur with the pointer that you pass:
{ ++f; }
But you cannot transfer the name of an array to a function, because the name of the array is associated with a certain number of elements, and therefore it can be considered as a constant link. Those. In the following function:
void foo1(int* const& f) { cout << *(f + 1) << " : " << *f << endl; }
you can pass the name of the array. The type of the argument does not allow performing actions with the pointer itself, and (f + 1) is another pointer.
In the following function:
void foo2(int* f){ ++f; }
You can pass both the array name and any pointer, since the argument is a different pointer, initialized with the same address. (copying takes place)
And finally:
void foo3(int& f) { ++f; }
It has an argument_of the object. Those. The function can be passed to the object, and all changes will occur with this object. In this case, the value of the object is incremented.
In order to better understand all this, write a test program for yourself. For example:
int a[] = {10, 20, 30}; int *m = a; foo2(m); cout << *m << " ... " << *a << endl; foo1(a); cout << *m << " ... " << *a << endl; foo(m); foo(a) // error foo2(a); cout << *m << " ... " << *a << endl; foo3(a[1]); cout << *m << " ... " << *a << endl;
*&fmeaningless. You can hang more paired taking of addresses and dereferencing, but why? - VTT&and*overloaded, but something realistic is what I find it difficult ... - VTTint x; foo1(&x);compiles, butfoo(&x)does not (in order forfoowork, you must first write the address to a variable). - HolyBlackCat 2:07 pmint a[10]; foo(a);- it won't even compile. What kind of "work with an array" are we talking about? - AnT