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

How can I find out if there are characters available for reading?

0 Answers  


What is c basic?

0 Answers  


what are the facialities provided by you after the selection of the student.

0 Answers   TCS,


What is union and structure in c?

0 Answers  


How can I manipulate individual bits?

0 Answers  


how to find the kth smallest element in the given list of array elemnts.

8 Answers   Silicon,


can we declare a function inside the structure? ex: struct book { int pages; float price; int library(int,float); }b; is the above declaration correct? as it has function declaration?

2 Answers  


Finding first/last occurrence of a character in a string without using strchr( ) /strrchr( ) function.

2 Answers  


what is the purpose of the code, and is there any problem with it. unsigned int v[10]; unsigned int i = 0; while (i < 10) v[i] = i++;

2 Answers   Google,


What is volatile c?

0 Answers  


What is scope rule in c?

0 Answers  


What is the explanation for prototype function in c?

0 Answers  


Categories