can’t we disallocate many memory and array arrays which are dynamically allocated by delete p, q, []arr; instead of writting them separately like delete p;
delete q;
delete []arr;
Delete operator deletion syntax for multiple variables
We can do that for pointers pointer to single entities, like we can do delete p,q;
. But for continuous memory we have to write in a separate line, i.e, we have to write delete[ ] arr
in separate line only.
Hope this help.
May you explain why we do so?
Because that is the defined syntax for the language. It’s not like that is the preferred convention or something, that is how the compiler is designed.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.