The short answer is that the pointer will not stay incremented.
In this example;
Code:
// include relevant_headers
void function(int *x)
{
x[0] = 5;
++x;
}
int main()
{
int arr[5] = {0}; // arr contains 5 zeros
int *orig_arr = arr; // store pointer to array
function(arr);
assert(orig_arr == arr);
assert(orig_arr[0] == 5);
assert(arr[0] == 5);
}
then ALL of the assertions will succeed.
Essentially, if the workings of a function change any argument that is passed by value to the function, then that change is not visible to the caller. If you want the change to be visible then, yes, you must pass either a pointer or a reference to the thing you want changed. If you want the change to a pointer to be visible, you must either pass a pointer to pointer or a reference to pointer. However, you cannot do that with an array;
Code:
// include necessary headers
void function(int **x, int *&y)
{
++(*x);
++y;
}
int main()
{
int *x = new int[5];
int *y = new int[5];
int *px = x; // store original pointers
int *py = y;
function(&x, y);
assert(x == px + 1);
assert(y == py + 1);
int arr[5];
int arr2[5];
function((int *)&arr, arr2); // undefined behaviour as arr and arr2 are really arrays not pointers
}