0

I couldn't figure out why commenting in and out the line changes a size from 16 to 24 even though it is a boolean? Also changing line order changes the total size of the struct, why is that?

struct product {
    bool test = true;
    bool test2 = true;
    bool test3 = false;
    bool test4 = false;
    bool test5 = false;
    bool test6 = false;
    bool test7 = false;
    char fortyTwo = 'a';
    // char sixtyNine = 'b';
    double d;
    // bool newBool; //Moving this line above double d changes the size as well
};


int main()
{
        product arr[3] = {};

        cout << sizeof(arr[1]) << endl;
        cout << arr << endl;
        cout << arr+1 << endl; 
    return 0;
}
ikegami
  • 343,984
  • 15
  • 249
  • 495

0 Answers0