Strcut padding?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • webinfinite@gmail.com

    Strcut padding?

    #include <iostream>
    #include <string>

    using namespace std;

    int main() {
    char t1;
    struct t2{
    char x;
    };

    cout << sizeof(t1) << " " << sizeof(t2) << endl;

    typedef char& x1;
    struct x2{
    x1 x;
    };

    cout << sizeof(x1) << " " << sizeof(x2) << endl;
    }

    output:
    1 1
    1 4

    Can anybody tell me why the size of x2 is 4? Why it's not 1?


Working...