Skip to content

Instantly share code, notes, and snippets.

@ybonnel
Created April 25, 2013 14:30
Show Gist options
  • Select an option

  • Save ybonnel/5460138 to your computer and use it in GitHub Desktop.

Select an option

Save ybonnel/5460138 to your computer and use it in GitHub Desktop.
@Test
public void testCalcul1() {
int i;
// Compile pas, on ne peux pas faire un '++' sur un int non-initialisé.
i = i++;
System.out.println(i);
}
@Test
public void testCalcul2() {
int i = 0;
// 0 je pense le ++ est fait après la récup de valeur mais avant l'affectation.
i = i++;
System.out.println(i);
}
@Test
public void testCalcul3() {
int i = 1;
// 2 je pense le ++ est fait après la récup de valeur mais avant l'affectation.
i = 1 + i++;
System.out.println(i);
}
@Test
public void testCalcul4() {
int i = 1;
// 5 : 1 + (2 (i+1)) + (2 (i du ++i))
i = 1 + ++i + i++;
System.out.println(i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment