C & C++

C & C++

Made by DeepSource

Assignment in condition should be parenthesized CXX-W1161

Bug risk
Major

Assignment in condition should be parenthesized, when used in a conditional operator. Otherwise there can be issues with precedence, as assignment is the operator with least precedence. Consider putting assignment in condition in round braces.

Bad practice

int x = 10;
if (x = x * 2 > 20) {  // This will assign x as false, not x * 2
    // ..
}

Recommended

int x = 10;
if ((x = x * 2) > 20) {
    // ..
}