How to check if your machine is Little Endian or Big Endian using C program in Linux

 $ vim check_endian.c 
[bash] #include <stdio.h> int main(int argc, char **argv) { int num = 1; if(*(char *)&num == 1) { printf("\nLittle-Endian\n"); } else { printf("Big-Endian\n"); } } [/bash]
 $ gcc -o check_endian check_endian.c 
 $ ./check_endian 

Leave a Comment