I'm having trouble converting an int into a float. I tried to type convert but it doesn't seem to work. What am I doing wrong?
float *six(const int *x) {
float *p = malloc(sizeof(x));
p = (float *)x;
return p;
}
int main() {
float *p_six;
int i4 = 4, i432 = 432;
p_six = six(&i4);
printf("%d == %f\n", i4, *p_six);
free(p_six);
}
p = (float *)x;assignment in the function obliterates the pointer to the memory allocated in the previous line, so you have a memory leak every time you call the function.