Following is a piece of C++ code which assigns integer variable address to character pointer.
int ia = (1<<25) + (1<<24) + (1<<17) + (1<<8) + 4;
char *cArr = (char *)(&ia);
int i;
for(i = 0; i < 4; i++){ cout << (int)cArr[i] << endl; }
I have chosen the integer variable so that the MSB byte can have a value of 3, the next value of 2, the next a value of 1 and the LSB byte a value of 4.
Now when I assign the integer's address to a character pointer then I get the following result:
cArr[0] = 4
cArr[1] = 1
cArr[2] = 2
cArr[3] = 3
I have some questions regarding this result:
- Is it always that the LSB byte will get the first address irrespective of the machine on which I am working.
- Has the result something to do with Little Endian and Big Endian. Also I am looking for some basic tutorial which can get me the basics of Little Endian and Big Endian.
- Has the result something to do with how the stack grows on a machine.
By the way I work on a windows PC

int ia = (1<<25) + (1<<24) + (1<<17) + (1<<8) + 4;int ia = 0x03020104or at leastint ia = (3 << 24) + (2 << 16) + (1 << 8) + (4 << 0).