pointer char ** changing when returning from function

I have a pointer char** being passed to Change function below and it looks find when it returns, and prints the correct value "Tom". But as soon as I execute any code after the return from the function Change, my pointer gets messed up. I've stepped through debug countless times.

1
2
3
4
5
void Change(char** &in)
{
    char *New[] = {"Tom", "Dick", "Bob"};
    in=New;
};



This is the call from main on line 8; The program chokes on line 10 and my pointer magically changes??
1
2
3
4
5
6
7
8
9
10
11
12
    char *Narry[] = {"Ken", "Dora", "Cally"};
    char** Harry=Narry;

    cout << Narry[0] << endl;
    cout << Narry[1] << endl;
    cout << Narry[2] << endl;

    Change (Harry);
    cout << Harry[0] << endl;
    cout << Harry[1] << endl;
    cout << Harry[2] << endl;

The function makes the pointer pointer point to an array that no longer exists
Thanks helios.
If I change the function to the following it works. I guess I don't understand pointers as well I as thought because I assumed line 3 and 4 were equivalent.

1
2
3
4
5
6
7
8
9
void Change(char** &in)
{
    //char *New[] = {"Tom", "Dick", "Bob"};
    char** New = new char*[3];
    New[0]="Tom";
    New[1]="Dick";
    New[2]="Bob";
    in=New;
};
Topic archived. No new replies allowed.