In C, dropping the result from malloc is not required and should not be performed. This can lead, for example, to the error with the #include <stdlib.h> error, so you do not have a prototype for malloc in scope. This, in turn, can lead to other errors and a lack of tolerance (although the worst offenders in this regard are now mostly outdated).
In C ++, you must specify the result of malloc to assign it to a pointer to any type other than void. However, if you really don't need to write code that can be compiled as C or C ++, you should generally avoid using malloc in C ++ and allocate memory with new .
Jerry Coffin
source share