简体   繁体   English

Java返回语句混乱

[英]Java return statement confusion

I just want to ask, what is the meaning to (--a,b)? 我只是想问一下,( - a,b)是什么意思? Can somebody explain to me. 有人可以向我解释。 Currently i just want to trace the calculation manually, but i was stuck. 目前,我只想手动跟踪计算,但是我陷入了困境。

This part of the code: 这部分代码:

else if (a%2 == 0) return (-a) * b + print_it(--a, b); 否则如果(a%2 == 0)返回(-a)* b + print_it( - a,b);

The expression --a is the pre-decrement operator, meaning: decrement the value of a before using it in the expression. 表达式--a是减前运算符,表示:在表达式中使用a 之前先减小其值。 Compare it with the expression a-- , which uses the current value of a in the expression and at the end of the evaluation, decrements it. 用表达进行比较a-- ,它使用的当前值a中的表达和在评价结束时,将它减。

The -- and ++ pre and post operators are an area where Java looks just like C or C++, but has significantly different rules. --++前置和后置运算符是Java看上去与C或C ++相似的领域,但规则却大不相同。

Evaluation can never appear to be delayed, and the results are fully defined. 评估永远不会延迟,并且结果已完全定义。 The key concept is to separate the side effects of an operator from its value. 关键概念是将运营商的副作用与其价值区分开来。

The general rules for expression evaluation are in Chapter 15. Expressions in the Java Language Specification. 表达式评估的一般规则在第15章中。Java语言规范中的表达式 The specifics for --a are in 15.15.2. --a的详细信息在15.15.2中。 Prefix Decrement Operator -- As a side-effect, it reduces the value of a by 1. The value is the value of a after the new value is stored. 前缀递减运算符-作为副作用,它将a的值减小1。该值是存储新值的a的值。

The postfix decrement has the same side-effect, performed at the same point in expression evaluation, but the value of the postfix decrement expression is the value of the variable before the new value is stored. 后缀递减具有相同的副作用,在表达式求值中的同一点执行,但后缀递减表达式的值是存储新值之前的变量值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM