Endian check in C
Posted
by webgenius
on Stack Overflow
See other posts from Stack Overflow
or by webgenius
Published on 2010-04-03T04:38:07Z
Indexed on
2010/04/03
4:43 UTC
Read the original article
Hit count: 383
c
Got this code snippet from some website:
int num = 1;
if(*(char *)&num == 1)
{
printf("\nLittle-Endian\n");
}
else
{
printf("Big-Endian\n");
}
Can anyone explain this step-by-step?
&num -> Adress of a
(char *)&num -> Type-cast address of a into a string
*(char *)&num -> Points to the first character of the string
Am I missing anything here?
© Stack Overflow or respective owner