C++ struct alignment refers to how the compiler arranges variables in memory on boundaries that match their data sizes. CPUs read memory in chunks (typically 4 or 8 bytes) rather than individual bytes; alignment ensures the hardware can fetch variables in a single, highly efficient memory operation.
struct Unoptimized {
char a; // 1 byte // 3 bytes of padding inserted here
int b; // 4 bytes
char c; // 1 byte // 3 bytes of trailing padding inserted here
}; // so total of 12 bytes in that 6 byts went to padding
struct optmized {
int b; // 4 bytes
char a; // 1 byte
char c; // 1 byte
// 2 trailing bytes
} // now the total is 8 bytes we save 4 bytes.