Search code examples
javamathoperator-precedenceassociativity

Clarification on math expression using prefix increment operator and bracket precedence


Given this code:

int p,k=8;
p=k*(++k-8);
System.out.println(p);

when ++k is evaluated k=9 and then that becomes k*(9-8) giving 9*1

int p,k=8;
p=(++k-8)*k;
System.out.println(p);

But this gives 9 as output


Solution

  • this is the class file your code compiled:

       int k = 8;
        byte var10000 = k;
        int k = k + 1;
        int p = var10000 * (k - 8);
        System.out.println(p);