pointer conversion problem
1)
Code:
float f = 65.00f;
int * ip = (int*)&f;
printf("%i", *ip);
prints garbage value instead. Why?
When i try to convert it double*, it prints 0.000000. I guess that it is because of the memory size difference of 4 bytes of float and 8 bytes of double.
When i try the similar between int* and char*, it converts fine, is it because of fact that C stores character as decimal equivalent?
2)
Code:
int * ip = (int[]){1,2,3,4};
ip[2] = 5;
workes fine. Why? Isn't it supposed to crash the program or cause so-called "undefined behaviour"?
Thank you