... would expect 6 to be printed. Any idea why?
x++occurs after the value has 5been read from x. Remember that what follows the statement returnis an expression. When an operator is reached return, this expression is evaluated (its value is determined), and then this resulting value is used as the return value of the function. So, myfunchere is the order of what happens:
- Enter the
tryblock. x (, x).- .
finally .x.- , 3.
, , x - 6, . x .
myfunc :
int y = x;
x++;
x ( , return x ), y, x. y . .
: foo "foo" 5 bar, "bar", :
int test() {
try {
return foo();
}
finally {
bar();
}
}
... foo, "foo", bar, "bar" test 5. , foo , (finally) ( ), : , return foo();, foo(). return x;: .