+1 vote

`#include <stdio.h> `

`int main() `

`{ `

`   unsigned char arr[2] = {0x01, 0x00}; `

`   unsigned short int x = *(unsigned short int *) arr; `

`   printf("%d", x); `

`   getchar(); `

`   return 0; `

`}`

Output on little endian and big endian respectively?

A. 1, 1

B, 256, 1

C. 1, 256

D. None of above

reshown Jun 5

+1 vote

If little endian machine is present then the variable x will accuire the value of 0000 0001 which is 1

If Big endian machine is present then the variable x will contain the value 1000 0000 (reverse) and %d quantifier will treat the number as is. hence 256
answered Jun 5 by (2,940 points)
In little endian lower address contains lower byte
And in big endian lower address contains higher bytes
So how are these hexadecimal # stored in array and how you are accessing them can you explain it little bit more either with diagram or with words.
i think u saying reverse in little endian higher byte at lower address however in big endian higher byte at higher address
Are you sure what you are saying?
Hello folks,
Sorry for the late reply.....was busy with chores
So, assuming integer holds 4 Bytes of space and our machine is byte addressable:

Little Endian:
100 101 102 103 (address of Byte)
01   00   00   00

And since, the integers are interpreted as usual (from MSB ---> LSB), hence the number will be 0000 0001 which is 1

Please understand that Endianess deals with arrangement of Bytes (as a whole) and not the bit orientation inside (this used to be my incorrect perception for a long time). Feel free to ask
please explain why the big endian gives 256 and not 128?