Created
November 12, 2014 10:14
-
-
Save nikAizuddin/75f5aa795e60f8082bcf to your computer and use it in GitHub Desktop.
How Java execute z = ++x + ++x + ++x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class test { | |
| public static void main(String[] args) { | |
| int x = 2; | |
| int z = 0; | |
| z = ++x + ++x + ++x; | |
| System.out.printf("z = %d\n",z); | |
| } | |
| } | |
| Disassemble: | |
| iconst_2 | |
| istore_1 // int x = 2; | |
| iconst_0 | |
| istore_2 // int z = 0; | |
| iinc 1, 1 // x = x + 1 | |
| iload_1 // get value x = 3 | |
| iinc 1, 1 // x = x + 1 | |
| iload_1 // get value x = 4 | |
| iadd // 3 + 4 = 7 | |
| iinc 1, 1 // x = x + 1 | |
| iload_1 // get value x = 5 | |
| iadd // 7 + 5 = 12 | |
| istore_2 // z = 12 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment