I'm trying to do the following
int a[8]={1,2,3,4,5,6,7,8};
printf("%f\n", *(float *)a);
printf("%f\n", *((float *)a+1));
printf("%f\n", *((float *)a+2));
printf("%f\n", *((float *)a+3));
printf("%f\n", *((float *)a+4));
printf("%f\n", *((float *)a+5));
printf("%f\n", *((float *)a+6));
printf("%f\n", *((float *)a+7));
I get
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
The reason why I'm trying to print the elements in this way is because, I want to cast the int pointer to the array to the float pointer and pass it as a parameter for another function which only takes float *
.
It seems that this does not work well. Can someone explain why this is not working?
int *ptr;
function((float *)ptr);
If I do this the function does not read the values the pointer is pointing to properly.. just returning 0.0000
.