Is the type cast necessary when using malloc in C?
I am learning how to use malloc, and I am seeing that most people think it's necessary to make a type cast when passing the memory address to the pointer. For example, here's a code to get 16 new bytes allocated (4 ints) using malloc:
My question: is the (int *) cast on the right side of the attribution necessary? After all p is already a pointer to ints, so the pointer arithmetic should work fine even without that cast.
p = (int *)malloc(4*sizeof(int));