I am trying to learn what is the difference between:
int *p = malloc(3 * sizeof(int));
ANDint *p = (int*)malloc(3 * sizeof(int));
when initializing a dynamic array in C, and I can't get it, any help?
I am trying to learn what is the difference between:
int *p = malloc(3 * sizeof(int));
AND
int *p = (int*)malloc(3 * sizeof(int));
when initializing a dynamic array in C, and I can't get it, any help?
In C there's no need for such operation, which is called cast, because a void*
pointer is implicitly convertible to any kind of pointer.
In C++ you would require it because there's no such implicit conversion, but you will be using new
instead that malloc
, which wouldn't require it at all.