+ 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; }

6th Apr 2018, 11:38 AM
RiGeL
RiGeL - avatar
4 Answers
+ 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.
6th Apr 2018, 11:40 AM
LunarCoffee
LunarCoffee - avatar
+ 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.
6th Apr 2018, 11:49 AM
LunarCoffee
LunarCoffee - avatar
+ 2
LunarCoffee thank you now its all clear :)
6th Apr 2018, 11:52 AM
RiGeL
RiGeL - avatar
+ 1
LunarCoffee thank you but also what do we mean when we say (Memory Leak )?
6th Apr 2018, 11:44 AM
RiGeL
RiGeL - avatar