C Questions and Answers – Endianness

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Endianness”.

Pre-requisite for this C Endianness MCQ set: Video Tutorial on C Endianness.

1. A machine in which the least significant byte is stored in the smallest address is __________
a) Big endian machine
b) Bi-endian machine
c) Binary bit machine
d) Little endian machine
View Answer

Answer: d
Explanation: In little endian machines, last byte of binary representation (least significant byte) of a multi byte data type is stored first, whereas in big endian method, the first byte of binary representation of a multi byte data type is stored first.

2. If the output of the following C code is “Big endian”, then what will be the value of *a is?

advertisement
advertisement
#include <stdio.h>
int main()
{
   unsigned int i = 1;
   char *a = (char*)&i;
   if (*a)
       printf("Little endian");
   else
       printf("Big endian");
   getchar();
   return 0;
}

a) -1
b) 0
c) 1
d) 2
View Answer

Answer: b
Explanation: In the code shown above, a character pointer ‘a’ points to an integer ‘i’. Since the size of the character is 1 byte, when the character pointer is de-referenced, it contains 1 integer byte. If the machine is a little endian machine then the value of *a will be 1, since the last byte is stored first. If the machine is big endian, the value of *a will be 0.
Note: Join free Sanfoundry classes at Telegram or Youtube

3. It is possible for a processor to support both little and big endian methods.
a) True
b) False
View Answer

Answer: a
Explanation: It is possible for a processor to support both little and big endian methods. Such machines are known as bi-endian machines.

4. The standard byte order for networks is ____________
a) Bit-Binary
b) Little endian
c) Big endian
d) Bi-endian
View Answer

Answer: c
Explanation: The standard byte order (network byte order) for networks is big endian. Before transferring data on a network, data is converted to big endian.
advertisement

5. Which of the following is not an example of big endian machines?
a) Power PC
b) Motorola 68K
c) SPARC processors
d) ARM processors
View Answer

Answer: d
Explanation: ARM processor is an example of little endian machine. Current generation ARM processor is an example of bi-endian machine. Power PC, Motorola 68K and SPARC are examples of big endian mahines.

6. Suppose we transfer a file written on a little endian machine to a big endian machine and there is no transformation from little endian to big endian, then what happens?
a) The big endian machine throws an error when it receives the file
b) The big endian machine reads the file in the reverse order
c) The big endian machine does not read the file
d) The big endian machine reads the file in the normal order
View Answer

Answer: b
Explanation: If there is no transformation from little endian to big endian on transfer of a file from a little endian machine to a big endian machine, the big endian machine reads the file in reverse order.
advertisement

7. File formats which have _________ as a basic unit are independent of endianness.
a) 1 byte
b) 2 bytes
c) 3 bytes
d) 4 bytes
View Answer

Answer: a
Explanation: File formats which have 1 byte as the basic unit are not endianness dependent. Eg: ASCII files. Other file formats have fixed endianness formats.

8. If the code shown below is executed on a little endian machine, then what will be the output of the following C code?

#include<stdio.h>
main()
{
    int y=1;
    printf("%d", (*(char*)&y));
}

a) 1
b) 1000
c) 9999
d) 0
View Answer

Answer: a
Explanation: The output of the above code will be one when it is run on a little endian machine. This is because a little endian machine stores the least significant byte in the smallest address.

9. If the data “ABCD” is to be stored in a little endian machine, it will be stored as _________
a) ABCD
b) DCBA
c) CDAB
d) BCDA
View Answer

Answer: b
Explanation: In a little endian machine, the least significant byte (right most) is stored in the smallest address. Hence the data “ABCD” will be stored in the form of “DCBA”.

10. The sequential order used to interpret a range of bytes in the memory of a computer is known as _________
a) Ordering
b) Sequencing
c) Endianness
d) Byte prediction
View Answer

Answer: c
Explanation: Endianness is the sequential order used to interpret a range of bytes in the memory of a system.

Sanfoundry Global Education & Learning Series – C Programming Language.

To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.