Write a small C program to determine whether a machine's
type is little-endian or big-endian.

Answers were Sorted based on User's Feedback



Write a small C program to determine whether a machine's type is little-endian or big-endian...

Answer / vasundhara

int main()
{
int x=1;

if(*(char*)&x)
printf("little endian");
else
printf("big endian");

return 0;
}

Is This Answer Correct ?    7 Yes 1 No

Write a small C program to determine whether a machine's type is little-endian or big-endian...

Answer / anuraag

Vasudhara's solution is correct!
Still here is an alternative solution to check endianess
without using pointers...

int main()
{
int x=0x58;
char ch;
ch=x;

if(ch=0x58)
printf("Little Endian");
else
printf("Big Endian");
return 0;
}

Is This Answer Correct ?    3 Yes 1 No

Write a small C program to determine whether a machine's type is little-endian or big-endian...

Answer / udita

little indian

Is This Answer Correct ?    5 Yes 8 No

Write a small C program to determine whether a machine's type is little-endian or big-endian...

Answer / sudheer

little india

Is This Answer Correct ?    2 Yes 8 No

Write a small C program to determine whether a machine's type is little-endian or big-endian...

Answer / mohana

The below code snipeet tells whether the system is little
or big endian.

int main()
{
int x=1;

if(x)
printf("big endian");
else
printf("little endian");

return 0;
}

Is This Answer Correct ?    7 Yes 24 No

Post New Answer

More C Interview Questions

Difference between pass by reference and pass by value?

0 Answers   TCS, TISL,


What is zero based addressing?

0 Answers  


What is the value of y in the following code? x=7;y=0; if(x=6) y=7; else y=1;

12 Answers   TCS,


What is the exact difference between '\0' and ""

3 Answers  


I need a sort of an approximate strcmp routine?

0 Answers  






When do you not use the keyword 'return' when defining a function a) Always b) Never c) When the function returns void d) dfd

0 Answers  


Why main is not a keyword in c?

0 Answers  


Is printf a keyword?

0 Answers  


What type is sizeof?

0 Answers  


what is the difference between call by value and call by reference?

5 Answers   Genpact, Global Logic, Infosys,


What are the types of pointers?

0 Answers  


What is #define in c?

0 Answers  


Categories