Computer Science, asked by Anuragmandal8765, 1 year ago

Change in pointers but retain change after function

Answers

Answered by anmoldeep268gmailcom
0
Because you are passing a copy of pointer. To change the pointer you need something like this:

void foo(int **ptr) //pointer to pointer
{
*ptr = new int[10]; //just for example, use RAII in a real world
}
or

void bar(int *& ptr) //reference to pointer (a bit confusing look)
{
ptr = new int[10];
}
Similar questions