Skip to content

Instantly share code, notes, and snippets.

@nikAizuddin
Created November 12, 2014 10:14
Show Gist options
  • Select an option

  • Save nikAizuddin/75f5aa795e60f8082bcf to your computer and use it in GitHub Desktop.

Select an option

Save nikAizuddin/75f5aa795e60f8082bcf to your computer and use it in GitHub Desktop.
How Java execute z = ++x + ++x + ++x
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