What happens to the memory location when I initialize a variable in c++ more than once? For example:
LPWSTR sampleString = new whcar_t[10];
//some operations here
sampleString = new wchar_t[2];
//some operations here
sampleString = new wchar_t[25];
//some operations here
If I delete the memory by using delete [] sampleString; will all the associated memory locations be cleared?
No, only the last one. All the rest will be lost forever. This is what is called “a memory leak”.