c++ - if(!(x%3)) 是什么意思?

标签 c++

我正在尝试解决一个硬件问题,我需要写下程序将输出的内容。然而,我被语法“if ( !(i%3)) 卡住了。这到底是什么意思?这是否意味着程序正在检查任何可被三整除的 i?也就是 if 语句是否只运行如果我能被三整除?

int main () {
for (int i=0; i<10; (i<3?i++;i+=2)) {
    if (!(i%3)) {
        continue;
    }
    else if (i%7 ==0) {
        break;
    }
    cout << i<< endl;
}

最佳答案

Does it mean that the program is checking for any i that is divisible by three? aka, is the if statement only runs if i is divisible by three?

正确。该支票的较长版本是

if (i % 3 == 0)
    continue;

这种分支最常见的用例可能是 FizzBuzz .

关于c++ - if(!(x%3)) 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58318150/

相关文章:

c++ - 没有调用正确的构造函数

c++ - unique_ptr 的临时只读拷贝

python - C-contiguous fashion在caffe blob存储中意味着什么?

c++ - 有没有办法绑定(bind) template<template> 参数?

c++ - C++中如何使用memset或fill_n初始化动态二维数组

c++ - 分拣程序

c++ - 在运行时在共享库中调试/跟踪?

c++ - 取消引用指针(并返回它)的问题

c++ - 从 32 位 Xcode 项目引用 64 位静态库

c++ - 从 Gradle 迁移到 CMake for C++ 项目