Can anyone explain to me why when I use the new prefix on a pointer in another method than I created it, it does not work as intended?
output is random numbers from memory.Code:#include <iostream>
void magic(int *T, int sz)
{
T = new int[sz];
for(int i=0;i<sz;++i)
T[i] = i;
}
int main()
{
int *T;
magic(T , 10);
for(int i=0;i<10;++i)
std::cout << T[i] << " ";
}
does T no longer point to the start of array when the method magic reaches it end?
Thanks!