'AND' vs '&&' as operator

后端 未结 10 611
野性不改
野性不改 2020-11-22 02:42

I have a codebase where developers decided to use AND and OR instead of && and ||.

I know that there is a

10条回答
  •  鱼传尺愫
    2020-11-22 03:10

    Another nice example using if statements without = assignment operations.

    if (true || true && false); // is the same as:
    if (true || (true && false)); // TRUE
    

    and

    if (true || true AND false); // is the same as:
    if ((true || true) && false); // FALSE
    

    because AND has a lower precedence and thus || a higher precedence.

    These are different in the cases of true, false, false and true, true, false. See https://ideone.com/lsqovs for en elaborate example.

提交回复
热议问题