0
struct test{
    int year;
    char text;
    double num;
};

int main ()
{

 test t;
 cout<<sizeof(t);
  return 0;
}

The result is 16, while I was expecting 13. Since sizeof(char) is 1. What am I missing here?

1 Answers1

1

C++ may add padding between members. The struct might therefore be larger than the added size of its members.

Oswald
  • 31,254
  • 3
  • 43
  • 68