使用枚举作为条件,if 条件将返回什么,真或假?
Using enum as a condition, what will the if condition return, True or False?
enum segment
{
OFF,
ON
};
int main()
{
segment indicator;
int temp_prev = 37;
int temp_curr = 39;
indicator = OFF;
if ((temp_curr > temp_prev and temp_curr > 39) or !indicator)
{}
这是了解enum
用途和属性的基本程序的一部分。
让我困惑的是,!enum
会返回什么,if
条件会返回什么?
(假设 C( 枚举存储为 int。在您的示例中,OFF 将默认为零,这在条件中被视为 false,任何非零值都将被视为 true。
让我
感到困惑的是
!enum
返回的内容
一元!
是逻辑 NOT 运算符。枚举值隐式转换为基础整数类型。如果该整数为 0,则结果为 true,否则为 false。OFF
的基础值为 0,因此在这种情况下结果为 true,整个条件也是如此。
相关文章:
- 我提出什么条件才能再加5%的折扣
- 在什么条件下使用 std::memcpy 在对象之间复制是安全的?
- 使用枚举作为条件,if 条件将返回什么,真或假?
- 正在连接的等待条件变量的线程会发生什么情况?
- 这个循环测试条件是什么意思?
- if 语句正在检查什么条件
- while 循环条件 c++ 中的","有什么用?
- 有什么东西阻止std::optional::value_or()有条件地不例外吗?
- Haskell中用多态性替换条件的等效模式是什么?
- 为什么 c++ 中需要条件来实现良好的编码实践,即使我们没有什么可写的
- 什么保证两个不相关的线程中的不同不相关对象没有(不可避免的)争用条件?
- 计算文本文件中行数的最佳条件是什么
- 在什么条件下,数据库在从 cpp 执行选择查询时不会关闭游标
- 当使用内存分配函数用作条件语句时会发生什么
- 在什么条件下,纯虚拟方法生成了
- 在条件上更新变量的最快方法是什么?
- 同时执行 if 和 else 条件的逻辑是什么
- #ifdef SWIG:什么时候考虑这种条件编译
- 什么可以唤醒条件变量
- 在 if 条件下调用什么重载运算符