a program to check whether a machine is little endian machine or Big endian machine

1 reply [Last post]
apeksha
Offline
Last seen: 7 years 7 weeks ago
Joined: 2009-09-18
bOt Points: 126

hi

i need a c or c++ code to check whether a machine is little endian machine or Big endian machine

shashwat
Offline
Last seen: 1 year 31 weeks ago
Joined: 2009-02-18
bOt Points: 1160
Program to determine big endian or little endian machine

Hi apeksha0701,

Check out this program 

#include<stdio.h>        

int x=1;

int main()

{

   (*(char*)&(x)==1)?printf("little endian"):printf("Big endian");
   return 0;
}

Try this out in Online C/C++ compiler. The output is shown below - 

 

Founder and Admin