Does deleting a pointer delete the memory it's pointing too?
问题 If I have a pointer like so: int *test = new int; And I create another pointer that points to test like so: int *test2 = test; Then I delete test2 : delete test2; Does that mean that it will delete the memory of test as well, or would I have to call delete test also? 回答1: Yes, the memory will be deleted freed as both pointers point to the same memory. Furthermore, test will now be a dangling pointer (as will test2 ) and dereferencing it will result in undefined behaviour . 回答2: You never