Addressing Modes- Q9

0 votes

#include <stdio.h>

int main()


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

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

   printf("%d", x);


   return 0;



Output on little endian and big endian respectively?

A. 1, 1

B, 256, 1

C. 1, 256

D. None of above

asked Jun 4 in Computer Organization by gbmentor (7,990 points)
reshown Jun 5 by gbmentor

3 Answers

+1 vote
Best answer
Correct Answer is C.

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 vinayakjhapro18 (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
0 votes

LIttle endian and Big Endian are standard for numbering the byte or word in actual physical address space,isn't it Sir ??
answered Jun 5 by soumyadeeppro20 (1,640 points)
0 votes
0x01 in hexa decimal but for printing hexadecimal value we used %p but here used %d so compiler read first 0 and think that value is 0 so 0,0 is the answer

So d is correct one.
answered Jun 5 by tsnikhilsharmagate2018 (7,480 points)
Integers are automatically type casted in C from one radix to another. You can confirm the same by writing a program that prints an int variable initialized to 0x01 and print using %d print formatter.