+ 2
For the code below..when we say 'delete p' we will delete ADDRES of the memory location that the P points to OR the VALUE 5???
#include <iostream> using namespace std; int main() { int *p = new int; // request memory *p = 5; // store value cout << *p << endl; // use value delete p; // free up the memory return 0; }
4 odpowiedzi
+ 3
It resets the memory at the location of p, leaving a dangling pointer (don't worry about that yet). Basically, it deletes the value in the memory, so the references to it are gone.
+ 2
RiGeL
A memory leak is when you allocate memory for something, use it, finish using it, then forget to deallocate it. This eventually causes the memory usage to build up every time that happens, gradually reducing performance and stability.
+ 2
LunarCoffee thank you now its all clear :)
+ 1
LunarCoffee thank you but also what do we mean when we say (Memory Leak )?