Tech Community Live: Windows edition
Jun 05 2024, 07:30 AM - 11:30 AM (PDT)
Microsoft Tech Community

Why the size of type Bar is 3 not 4 in MSVC?

Copper Contributor
#include <iostream>
using std::cout;

struct Bar {
    char name[3];
    struct Foo {
        int a;
        int b;
    };
};

int main()
{
    cout << sizeof(Bar);
    return 0;
}

Usually it aligns so it's multiple of sizeof(int).

0 Replies