C++ deleting a pointer when there are 2 pointers pointing to the same memory locations

后端 未结 4 1929
既然无缘
既然无缘 2020-12-17 07:26

Lets say, I have one pointer

int *l1 = new int[100*100];

int *l2 = l1;

Now, l1 & l2 both point to the same sequ

4条回答
  •  天涯浪人
    2020-12-17 08:09

    I2 is not deleted. I2 is now a pointer pointing to a place where you have no idea what is stored. This is because delete[] I1 deletes the variable I1 references not the pointer itself.

提交回复
热议问题