If I reallocate memory with 'new' it will erase what was written to the buffer but if I assign it to another pointer before reallocating, I can still print out what was there with the other pointer.
How is that possible when the second pointer points to the same address as the first?
Code:int main() { long iWholeSize = 17; char * buf = new (nothrow)char[iWholeSize]; buf = "hello"; char *pch = buf; buf = new (nothrow)char[iWholeSize+10]; cout << "buf " << buf << "\n"; cout << "pch " << pch << "\n"; delete[] buf; return 0; }