To be more precise about what others are saying, here is a test:
#include <stdlib.h> int main() { int a = 10; float b = 10; char * p; p = &a; printf("int repr: %02x %02x %02x %02x\n", p[0], p[1], p[2], p[3]); p = &b; printf("float repr: %02x %02x %02x %02x\n", p[0], p[1], p[2], p[3]); return 0; }
Output signal
int repr: 0a 00 00 00 float repr: 00 00 20 41
It shows:
a) This is a little finite machine, since the low byte of int comes first into memory b) int has a representation with bytes 0a 00 00 00 , so the value is 0000000a , a hexadecimal representation, well, 10. c) the float is really 41200000 . According to IEEE 754 , this means that you have one sign bit, 8 exponent bits, and 23 mantissa bits. The sign is 0 (+), the exponent is 0x82 , which means +3, and the mantissa is 010000... , which means 1.01 in binary or 1.25 in decimal.
Together, these data form the value 2 * 2 * 2 * 1.25 = 8 * 1.25 = 10.
source share