Yup as told by gerard4143 and asit mahato.
Saurav:-Don't get confused by seeing negative sign as output.
int i = 449; int *iPtr = &i;
printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) );}
output is -> -63 1.
As binary of 449 is 00000001 11000001
for 11000001, most significant bit(MSB) is 1 which is sign bit if there is 0 means number is positive and if there is 1 i.e, number is negative here it is 1 means number is negative. so converts this binary into its 2's complement which is 00111111(63 in decimal but -(minus) sign will be there because of 1 in MSB so -63).
for 00000001 MSB is 0 so number is positive and nothing to worry.
now final binary form is:--
= 1 -63 (in decimal)
so output will be -63 and 1.
Motorola, Solaris processors use "Big Endian" byte order.
google it for more information..
Now whats happening here iPtr is a pointer storing integer address.
iPtr will represent the same address as represented by casting it with char i.e, (char*)iPtr.
but here we are limiting the value at that address to 1 byte instead of sizeof(int) byte by casting it, and we are returning the value as an int not as a char.
so 1 byte= 8 bits. and that binary conversion , the little endium things (as intel processor) are taken into consideration for value at address of (char*)iPtr and next bit for (char*)iptr+1.
:icon_idea: MUST GO THROUGHTHE LINK FOR YOUR ALL DOUBTS ABOUT POINTERS, MEMORY, INPUT NUMBERS AND DATA CHARACTERS..