一元操作员是否真的首先被执行?

发布于 2025-02-01 03:01:43 字数 819 浏览 2 评论 0原文

我有关于优先事项的问题。 Java指出,这是解决操作员(从高到低)的优先事项:

  1. 后缀一单位OPARTORS XYZ ++,XYZ--
  2. fixunary opartors ++ xyz,-xyz
  3. TypeConversion / casting / casting / casting
  4. “* /%
  5. ”+ - + -
  6. <<<< >>
  7. < < => > =
  8. ==,!=
  9. &
  10. 独家
  11. |
  12. &&
  13. ||
  14. ?:
  15. =, +=, - =, *=, /=,%=

现在,如果您查看单一操作员,他们说:

在单一邮政邮局中,表达式之后将执行Unary。

这意味着,如果您有:

int a = 2;
int b = a++ * 3;

int b将为6,则表达式之后仅获得+1。

在一元前固定中,Unary在表达式之前被执行:

int a = 2;
int b = ++a * 3;

int b将为9。

我的问题是,这并不意味着后缀的单一操作员应该在第6号,前缀为1号?我看错了什么?

I have this question regarding priorities. Java states that this is the priority to work out operators (from high to low):

  1. postfix unary opartors xyz++, xyz--
  2. prefixunary opartors ++xyz, --xyz
  3. typeconversion/casting
  4. "* / %
  5. "+ -
  6. << >>
  7. < <= > >=
  8. ==, !=
  9. &
  10. exclusive
  11. |
  12. &&
  13. ||
  14. ?:
  15. =, +=, -=, *=, /=, %=

Now, if you look at unary operators, they state that:

In the unary postfixnotation , unary gets executed after the expression.

Meaning that if you have:

int a = 2;
int b = a++ * 3;

int b will be 6, cause a only gets +1 after the expression.

in the unary prefixnotation, unary gets executed before the expression:

int a = 2;
int b = ++a * 3;

int b will be 9.

My question is, doesnt this mean that postfix unary operators should be at number 6 and prefix at number 1? What am I seeing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遇见了你 2025-02-08 03:01:43

在评估IS a之后,将应用一元运算符的“表达式”,而不是任何表达式可能是其中的一部分。

The "expression" that the unary operator is applied after the evaluation of is a, not any expression it might be part of.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文