In C (but not C++), casting the return value of malloc is unnecessary because void* automatically converts to any pointer type. In fact, explicit casting can hide errors if you forget to include stdlib.h. The cast is only necessary in C++ or when compiling C code with a C++ compiler.