在算数运算中,能否将 bool 值 true 视作 1?

2023-06-09,,

true == 1;
true + 1;

If the destination type is bool, see 4.12. If the source type is bool, the value false is converted to zero and the value true is converted to one.

算数运算bool 类型会被提升成整型,true 会被转换成 1false 会被转换成 0

参考资料

ISO/IEC 14882:2011(E)
Can I assume (bool)true == (int)1 for any C++ compiler?

在算数运算中,能否将 bool 值 true 视作 1?的相关教程结束。

《在算数运算中,能否将 bool 值 true 视作 1?.doc》

下载本文的Word格式文档,以方便收藏与打印。