Let us suppose I define an integer variable in C++. Can I delete the variable using delete operator after a few commands?
Asked
Active
Viewed 40 times
0
-
7Sounds like you could use a [good C++ book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) – NathanOliver Mar 17 '17 at 17:22
-
I smell homework ;) – turnip Mar 17 '17 at 17:22
-
1if you mean something like `int val; val = 42; delete val;` then no. If not, then your question needs expansion. – user4581301 Mar 17 '17 at 17:22
-
1You can only `delete` an object that was allocated with `new`. Anything else is an error. – François Andrieux Mar 17 '17 at 17:25
-
In a mirror to the placement new operator, you can directly use the object's destructor (however, the memory itself is not associated with a heap so cannot be `free`d, it just doesn't make sense). – maxbc Mar 17 '17 at 18:43
-
@Petar, it's no homework – Aaron John Sabu Mar 18 '17 at 09:37
-
@user4581301 yes that is what I meant and thanks – Aaron John Sabu Mar 20 '17 at 18:13