i can't type casting of pointer.. have found garbage value of y. doing wrong in code?. please me find desire output
#include<stdio.h> int main(){ float x= 15; int *y; y=(int *)&x; printf("\tvalue of x : %f \n",x); printf("\tvalue of y : %d",*y); return 0; }
output
float x= 15; int *y; y =(int *)&x;
assigning address of float
pointer int
undefined behavior, not same type , not interchangeable, types allowed char *
, void *
.
change to:
float x= 15; char *y; y = (char *)&x; printf("\tvalue of x : %f \n", x); printf("\tvalue of y : %d", (int)*(float *)y);
or
float x= 15; void *y; y = &x; printf("\tvalue of x : %f \n", x); printf("\tvalue of y : %d", (int)*(float *)y);
Comments
Post a Comment