Chapter - 5: Classes in C++

Point out the reasons why new is a better idea than using malloc()?


D
Sections
3
Exercises

Points telling sweetness of new over malloc() is as follows:

1. There's no need to tell the number of bytes to be allocated in new, but in malloc().
2. There's no need for typecasting in new, but in malloc().
3. We can initialize the variable at the time of allocating values.
4. It is a bit easier to write than malloc().
5. We can create array just by giving the index size, but in malloc() we have to calculate the array size.


© 2021 Garbage Valuegarbage value logo