+ 2
What dose " delete " mean in Cpp ?
Cpp
11 ответов
+ 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.
+ 2
It deletes the object from memory.
+ 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.
+ 2
thank you...and " new " also mean what ?
+ 1
Thank you... which deferent between storing a pointer or variable in the heap and storinh them in the stack
+ 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.
+ 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
+ 1
thanks a lot Mr Akarsh Agarwal
+ 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 ?
+ 1
Thanks..Python...no..i'm just a biginner
0
ok