search

Home  >  Q&A  >  body text

java - 单目运算符问题;

int a=4;
b=a*a++;
b的结果?

单目运算符优先级比双目运算符高,理应是先累加然后相乘得到20,为什么程序运算结果是16?

PHPzPHPz2766 days ago600

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 10:19:44

    int a = 4;
    int b = a*++a; // 20

    The priority of increment and decrement is indeed higher than *. For example, in the above example, is operated first ++a

    But there is still a difference between ++a a++

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 10:19:44

    a++ takes the value first and then calculates the increment by 1, ++a takes the value first and then takes the value

    reply
    0
  • Cancelreply