Explain the difference between big-endian and little-endian byte ordering. Why does this matter when writing portable C++ code?

Last updated 21 June 2026

  • Endianness is the byte order of multi-byte values in memory. Big-endian stores the most significant byte first (network order), little-endian stores the least significant first (x86, ARM).

  • It breaks portability when raw bytes cross boundaries (files, networks, other hardware), since the same bytes decode to different values.

  • Pick a fixed serialization order and convert with htonl/ntohl, C++20 std::endian/std::byteswap, or explicit byte shifts instead of dumping struct memory.

  • https://www.geeksforgeeks.org/dsa/little-and-big-endian-mystery/
  • https://keasigmadelta.com/blog/how-to-convert-endianness-in-c-c-in-4-different-ways/
  • https://dataford.io/interview-guides/questions/detect-system-endianness-in-c
All C++ interview questions