question regarding to C#include
#include
#include
int main()
{
int n = 3;
double *tptr = malloc(n*sizeof(double));
if (tptr != NULL)
free(tptr);
return 0;
}
got such error:
error C2440: 'initializing' : cannot convert from 'void *' to 'double *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
what's wrong with it? Thanks
replace double *tptr = malloc(n*sizeof(double));
with double *tptr = (double *) malloc(n*sizeof(double));
you need an explicit cast since malloc returns pointers of type void *. otherwise compiler will complain.
you need an explicit cast since malloc returns pointers of type void *. otherwise compiler will complain.