Possible Duplicate:
Do I cast the result of malloc?
What is the Best Practice for malloc?
Im new with c language and i have a question as i was explained in class:
The type of the pointer returned by malloc() is void *, and therefore we need to cast it into the required type
which means i need to do:
char *str;
str = (char *) malloc(14);
but i dont understand, is it a must? lets say malloc returns that void pointer, why do i see many of examples around without doing the casting? an example:
float *arr = malloc (20 * sizeof (float));
Could anyone please explain :) ?