c++ - if 语句正在检查什么条件

标签 c++

<分区>

所以我正在查找有关 2D Haar 小波变换的代码。还有这个 if 语句让我感到困惑。

部分代码如下所示:

unsigned char indexMask[4]; // the '4' here supposed to be a variable but I'm going to keep it simple here

for (int k = 0; k < 4; k++) {
indexMask[k] = 0;
}

for (int j = 1; j <= 5; j+=2) {
    if (indexMask[j/2]) {
        //some codes here
    }
}

我的困惑是,这里的 if 语句检查什么?这是我第一次看到以这种方式构造的 if 语句,所以我有点困惑。 非常感谢

最佳答案

来自 cppreference (仅引用相关部分):

if ( condition ) statement-true

condition     -   expression which is contextually convertible to bool

通俗地说:数字可以转换为bool0 转换为 false,其他所有内容都转换为 true

因此,条件也可以写成

if (indexMask[j/2] != 0) {
    //some codes here
}

关于c++ - if 语句正在检查什么条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57705600/

相关文章:

c++ - 查找字符串中是否存在某些字符

c++ - 询问 CFSTR_PRINTERGROUP 时出现错误 DV_E_FORMATETC - Windows 7

c++ - 嵌入式系统的独立于硬件的C++ HAL

c++ - 对 `icu_56::UnicodeString::UnicodeString(signed char, unsigned short const*, int)' 的 undefined reference

c++ - 如何在使用 Win32 API 创建的窗口上添加淡入/淡出效果

c++ - 如何优化和加速 C++ 中的矩阵乘法?

c++ - 如何最好地将私有(private)继承公开给基类?

c++ - 用于从套接字接收消息的无限循环内 sleep 的替代方式

c++ - 如何摆脱 SQL 查询的字符串连接

c++ - 如何使 FFmpeg C++ 代码不输出错误消息?