Why do we cast malloc
, as in the following?
ptd = (double *) malloc(max * sizeof(double));
What is malloc
's normal return type? Why do we need to cast it?
Why do we cast malloc
, as in the following?
ptd = (double *) malloc(max * sizeof(double));
What is malloc
's normal return type? Why do we need to cast it?
This is malloc prototype
void *malloc(size_t size);
Generally no need to do typecasting.
From a standard guide:
Declaration:
void *malloc(size_t size);
Allocates the requested memory and returns a pointer to it. The requested size is size bytes. The value of the space is indeterminate. On success a pointer to the requested space is returned. On failure a null pointer is returned.
That should be everything!