Is there any difference between the Java and C++ operators?

前端 未结 6 1025
后悔当初
后悔当初 2021-01-12 00:16

If you take Java\'s primitive numeric types, plus boolean, and compare it to C++ equivalent types, is there any difference what concerns the operators, like precedence rules

6条回答
  •  滥情空心
    2021-01-12 00:30

    • For an expression like:

      a = foo() + bar();
      

      In Java, the evaluation order is well-defined (left to right). C++ does not specify whether foo() or bar() is evaluated first.

    • Stuff like:

      i = i++;
      

      is undefined in C++, but again well-defined in Java.

    • In C++, performing right-shifts on negative numbers is implementation-defined/undefined; whereas in Java it is well-defined.

    • Also, in C++, the operators &, | and ^ are purely bitwise operators. In Java, they can be bitwise or logical operators, depending on the context.

提交回复
热议问题