int x = 1;
char *y = (char*)&x;
what y is?
Suppose we are on a 32-bit machine.
If it is little endian, the x
in the memory will be something like:
higher memory
----->
+----+----+----+----+
|0x01|0x00|0x00|0x00|
+----+----+----+----+
A
|
&x
so *(char*)(&x) == 1
, and *y+48 == '1'
.
If it is big endian, it will be:
+----+----+----+----+
|0x00|0x00|0x00|0x01|
+----+----+----+----+
A
|
&x
so this one will be '0'
.