I have a question regarding dynamic memory allocation.
When it comes to C, memory is allocated using the functions malloc(), calloc() and realloc() and de-allocated using free().
However in objected oriented languages like C++,C# and Java, memory is dynamically allocated using the new and deallocated using delete keywords (operators) in case of C++.
My question is, why are there operators instead of functions for these objected oriented languages for dynamic memory allocation? Even when using new, finally a pointer is returned to the class object reference during allocation, just like a function.
Is this done only to simplify the syntax? Or is there a more profound reason?
newin those languages does more than just allocate memory). - Some programmer dudenewat all. The usual non-authorative answer is "because C++" (which is funny, becausenewin C++ is quite often code smell). At some point the designers of Java thought it was a good idea (I am yet to be convinced it was.) And the designers of C# probably did it "because Java". - juanchopanzanew,new[],deleteanddelete[]. Mix them as you please. And they can be overloaded by the application programmer. As for Java and C# merely copy/paste the operator names from C++. And since they have garbage collection, they don't care about delete. - Lundin