+ 2

What dose " delete " mean in Cpp ?

Cpp

18th Sep 2018, 4:27 PM
Abdelhaq
Abdelhaq - avatar
11 Antworten
+ 2
'new' means memory heap allocation for new data object. int* p = new int(5); It creates integer value in the memory heap, places 5 into it and places it's address into p variable. delete p; It destroy integer value in the memory heap and release memory for future use. It is important to understand, that pointer p could be copied multiple times, stored at global variable, returned from function while there is only one value in the memory heap.
18th Sep 2018, 7:43 PM
Sergey Ushakov
Sergey Ushakov - avatar
+ 2
It deletes the object from memory.
18th Sep 2018, 4:49 PM
Károly Komjáti
Károly Komjáti - avatar
+ 2
cpp doesn't have a garbage collector. It means that you are responsible to release memory after use. Each call of 'new' operator should have correspond 'delete' call.
18th Sep 2018, 5:56 PM
Sergey Ushakov
Sergey Ushakov - avatar
+ 2
thank you...and " new " also mean what ?
18th Sep 2018, 7:29 PM
Abdelhaq
Abdelhaq - avatar
+ 1
Thank you... which deferent between storing a pointer or variable in the heap and storinh them in the stack
18th Sep 2018, 7:55 PM
Abdelhaq
Abdelhaq - avatar
+ 1
Variable (pointer is also variable) on the program stack exist only inside function. All function variables destroyed when the function returns. Objects in the memory heap lives until they are deleted.
19th Sep 2018, 3:15 AM
Sergey Ushakov
Sergey Ushakov - avatar
+ 1
Abdelhaq If you need a memory allocated in run time we use (New and delete ) operator when you create a object via run time (compiler don't know if you compile it .it doesn't know what memory you allocate it but when you use (new) keyword STEP 1 . USE A CHARACTER POINTER char *p=new int(10). STEP 2. after when you run using object file it use it dynamic it this is use of new keyword STEP 3: USE (DELETE) if you delete your memory which you make it runtime the Delete operator use it that's type you use new keyword as that same use (delete=p); THE MEMORY WILL DELETED Thankyou Akarsh Agarwal
19th Sep 2018, 4:11 AM
Akarsh Agarwal
Akarsh Agarwal - avatar
+ 1
thanks a lot Mr Akarsh Agarwal
23rd Sep 2018, 10:51 AM
Abdelhaq
Abdelhaq - avatar
+ 1
its ok if you need anything new in Cpp you talk me but may i know a ques. for u you have any knowledge for phython ?
23rd Sep 2018, 10:57 AM
Akarsh Agarwal
Akarsh Agarwal - avatar
+ 1
Thanks..Python...no..i'm just a biginner
23rd Sep 2018, 10:59 AM
Abdelhaq
Abdelhaq - avatar
0
ok
23rd Sep 2018, 4:48 PM
Akarsh Agarwal
Akarsh Agarwal - avatar