Can a bool variable store more than 0x01?

后端 未结 6 1131
慢半拍i
慢半拍i 2021-01-21 09:48
#include 
#include 

using namespace std;

int main()
{
    bool a = 0x03;
    bitset<8> x(a);
    cout<

        
6条回答
  •  爱一瞬间的悲伤
    2021-01-21 10:19

    §4.12 Boolean conversions [conv.bool]

    1 A prvalue of arithmetic, unscoped enumeration, pointer, or pointer to member type can be converted to a prvalue of type bool. A zero value, null pointer value, or null member pointer value is converted to false; any other value is converted to true. A prvalue of type std::nullptr_t can be converted to a prvalue of type bool; the resulting value is false.

提交回复
热议问题