Java和C ++操作符之间有什么区别吗? [英] Is there any difference between the Java and C++ operators?

查看:159
本文介绍了Java和C ++操作符之间有什么区别吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你使用Java的原始数字类型,加上布尔值,并将其与C ++等价类型进行比较,是否存在与运算符有关的任何差异,如优先规则或位操作运算符?或者括号的效果?

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 or what the bit-manipulation operators do? Or the effect of parenthesis?

另一种方式,如果我拿一个Java表达式,并试图编译和运行它在C + +,它总是编译,总是给同样的

Asked another way, if I took a Java expression and tried to compile and run it in C++, would it always compile and always give the same result?

推荐答案



    • For an expression like:

      a = foo() + bar();
      

      在Java中,评估顺序已明确定义(从左到右)。 C ++不指定是否先评估 foo() bar()

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

      喜欢:

      i = i++;
      

      在C ++中未定义,但在Java中也已定义好。

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

      在C ++中,对负数执行右移是实现定义的/未定义的;

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

      此外,在C ++中,运算符& | ^ 是纯位运算符。在Java中,根据上下文,它们可以是按位或逻辑运算符。

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

      这篇关于Java和C ++操作符之间有什么区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆