Possible duplicate:
Can I pass the result to malloc?
I just found out how to use the malloc function, and my teacher noted that when passing a memory address to a pointer, it is necessary to do a type listing. For example, here is the code to get 16 new bytes (4 intervals) using malloc:
#include <stdlib.h>
int main(){
int *p;
p = (int *)malloc(4*sizeof(int));
return 0;
}
My question is: is there an (int *) listing on the right side of the attribution? After all, p is already a pointer to ints, so pointer arithmetic should work fine even without this.
thank
source
share