int main() { int *ptr = new int(5); delete ptr; // ptr становится висячим указателем. std::cout << sizeof(ptr); // у меня выводит 4 байта. // ... какие-то действия в коде // } I declare a pointer that takes 4 bytes in my memory, delete it somewhere at the beginning of the body (as far as I know, delete only frees the memory in which the pointer was located), what happens to the pointer itself? Why does he still occupy some memory? After all, this can affect the speed of my program if I create hundreds of pointers, delete them, and they will still take up some space.
ptris a local variable in themainfunction. Local variable cannot be "deleted". She will retire on completion of the block.deletehas nothing to do with it. Why did you add thisdelete? - AnTvoid f(){{int*x=..}{int*y=..}{int*z=..}}. The addresses of the variables x, y, z will be the same. - AlexGlebe 8:32 pm