First you have to know int is a 4 bytes quantity
, char is a 1 byte
.
When the machine read an integer, it will read consecutive 4 bytes. And read 1 byte for char.
In your case, you first declare an array orange[5], which is consecutive 5 bytes on the machine. And you assign 1 for each byte. So you will get something like this on your machine
0000 0001 0000 0001 0000 0001 0000 0001 0000 0001
And variable orange is a pointer pointing to the first byte. If you cast orange to char *
and dereference it, the machine will try to read a char on this address (orange), so you will get
0000 0001
If you cast orange to int pointer, the machine will try to read 4 bytes starting from orange, so you will get this.
0000 0001 0000 0001 0000 0001 0000 0001
If you turn this binary number into decimal, you will get 16843009
Hope it helps :)