How can We Prove that C Language (Microprocessor) is Following Little-Endian Method to Store Values?
[* For Intel x86/x86_64 Not for BM Power PC Thanks Josh for Comment]
void main()
{
int i=9;
char *p;
clrscr();
p = (char) &i ;
printf("\n First Byte : %d",*p);
p++;
printf("\n Second Byte : %d",*p);
getch();
}
You will Get Answer
First Byte : 9
Second Byte : 0
It proves that C is using Little-Endian.
[* For Intel x86/x86_64 Not for BM Power PC Thanks Josh for Comment]
void main()
{
int i=9;
char *p;
clrscr();
p = (char) &i ;
printf("\n First Byte : %d",*p);
p++;
printf("\n Second Byte : %d",*p);
getch();
}
You will Get Answer
First Byte : 9
Second Byte : 0
It proves that C is using Little-Endian.
The C language is not little endian. Rather the processor you compiled and ran this program is (likely Intel x86/x86_64). If you ran this same program on IBM Power PC, it would show big endian. The C language does not define the endianness, the microprocessor does.
ReplyDeleteThanks you very much Josh for your Knowledgeable Comment.
ReplyDeleteI will surely update my post....