How a bool type variable is stored in memory? (C++)

后端 未结 3 2002
不知归路
不知归路 2021-01-18 05:44

bool test;

sizeof(test) = 1 if using VS 2010. Since every C++ data type must be addressable, the \"test\" bool variable is 8-bits(1 byte).

My qu

3条回答
  •  滥情空心
    2021-01-18 06:00

    Another possibility to have a variable of 1 bit, is to put into a bitfield struct:

    struct {
        int a:1;
        int b:1;
    };
    

提交回复
热议问题