Regarding memory alignment and data packing, which of the following is true for structs in C++? 

  • Struct members are always packed tightly with no padding. 
  • Structs cannot be aligned in memory. 
  • Struct members have a defined order, but might have padding. 
  • Structs use dynamic memory for data storage.
Memory alignment and data packing are important considerations in C++ for optimizing memory usage and performance. In a struct, the order of declaration of members matters because the compiler might introduce padding between members to align data appropriately for the target architecture. This can affect the overall size of the struct.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *