Do not use the assignment operator in the following cases contexts because it typically indicates programmer error and can result in unexpected behavior:
- Controlling expression of
if
,switch
(selection statement (controlling expression) while
(controlling expression)- Controlling expression of
while
,do ... while
(iteration statementcontrolling expression) - S
econd operand of for
(iteration statementsecond operand) - First operand of
?:
(selection statementfirst operand) &&
(either operand)- Either operand of
||
or&&
(logical operators) - comma operator (second operand) Second operand of comma operator when the comma expression is used in any of these contexts
- Second and third operands of
?:
(selection statementsecond or third operands) where the ternary expression is used in any of these contexts
...