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

 $ vim check_endian.c 
#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");
        }
}
 $ gcc -o check_endian check_endian.c 
 $ ./check_endian 
READ  How to check which header belongs to which package in ubuntu

Leave a Reply

Your email address will not be published. Required fields are marked *