2*5+(6+3)*3 = 10 + 9*3 = 10+27 = 37.
Though I'm sure that the order of evaluation is undefined, so you shouldn't do this. Though this is ugly, so you shouldn't do this anyway..
Sorry there is a bug, my fault
2*5+(6+3)*3=37 it should be but it is 39
I have this on the software engineering classes. In java the result is 37. Why is the result different?
Well, ++x does the following: Before the entire statement is executed, add 1 to x. So before 2*x+(x+3)*3 is calculated, x becomes 5+1 (=6). Therefor, the outcome is not 2*5+(6+3)*3, but 2*6+(6+3)*3 = 37.
I don't know about Java, it's probably defined in a different way there.
The expression 2*x+(++x+3)*3 is an error, classified as "undefined behavior". It is as severe as accessing an array out of bounds: the language specification (both C++ and C) says that the compiler is free to crash and burn and not as much as warn you.
What happens is you are incrementing x (on the right side of the +) and reading from x (on the left side of the +) between sequence points. In C++ (and C) order of evaluation of operands is unsequenced. Depending on the situation, the compiler may read from x (on the left side of the +) before, after, or simultaneously with writing to x (on the right side of the +). The left x may evaluate to the value of x before ++x, the value of x after ++x, or some half-written value.
In practice, all compilers I know compile this (some, like GCC, with warnings which you should never ignore!), but the results are completely unpredictable.
Here, I tested a few:
gcc 4.6.2/linux: 39
clang++ 2.9/linux: 37
Intel C++ 11.1/linux: 39