c++ i == 1 || 3 || 5 || 7 || 8 || 10 || 12
时间: 2023-10-23 08:12:17 浏览: 37
This expression is not valid in C.
When evaluating an expression that involves multiple conditions connected with logical operators (such as || or &&), each condition must be evaluated separately and compared to a Boolean value (true or false).
In this case, the expression "i == 1" would be evaluated first, and if it is true, then the entire expression would be true. However, if "i == 1" is false, then the expression "3" would be evaluated next. Since "3" is a non-zero value, it would be interpreted as true, and the entire expression would be true regardless of the value of "i".
To correctly express the intended logic, the expression should be written as follows:
(i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12)