Doesn't malloc(); function return a void pointer? Then why in the malloc(); module in C, the type casting is not used? | SoloLearn: Learn to code for FREE!

0

Doesn't malloc(); function return a void pointer? Then why in the malloc(); module in C, the type casting is not used?

4/19/2020 8:09:19 AM

Manthan Gohel

2 Answers

New Answer

+4

In C conversion from type* to void* and visa-versa is implicit. In C++ type* to void* is implicit but from void* to type* requires explicit cast.

+3

I'm more concerned with the absence of `free` usage example in examples involving dynamic memory allocation. Also the pointer validity verification before use is not included in examples. But maybe it's just to keep the examples short, and easier to digest.