15.6.1
Evaluate Left Hand Operand First
EXPRESSIONS
Thus:
class Test {
public static void main(String[] args) {
int i = 2;
int j = (i=3) * i;
System.out.println(j);
}
}
prints:
9
It is not permitted for it to print
6
instead of
9
.
If the operator is a compound assignment operator ( 15.25.2), then evaluation
of the left hand operand includes both remembering the variable that the left hand
operand denotes and fetching and saving that variable's value for use in the
implied combining operation. So, for example, the test program:
class Test {
public static void main(String[] args) {
int a = 9;
a += (a = 3);
//
first example
System.out.println(a);
int b = 9;
b = b + (b = 3);
//
second example
System.out.println(b);
}
}
prints:
12
12
because the two assignment statements both fetch and remember the value of the
left hand operand, which is
9
, before the right hand operand of the addition is
evaluated, thereby setting the variable to
3
. It is not permitted for either example
to produce the result
6
. Note that both of these examples have unspecified behav
ior in C, according to the ANSI/ISO standard.
If evaluation of the left hand operand of a binary operator completes abruptly,
no part of the right hand operand appears to have been evaluated.
Thus, the test program:
306
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved