Endian check in C
- by webgenius
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?