+ 1

Precedence of postfix, prefix vs operator

Can anyone explain to me why the output of the following code is 14, not 13? And what is the precedence between postfix, prefix and arithmetic operators? { int x =4; int y = ++x*4/x+x; System.out.print(y+x); } Thanks a lot <3

14th Jan 2018, 8:01 AM
Tien Dat Dang
Tien Dat Dang - avatar
2 Respuestas
+ 17
x=4 y=5*4/5+5 //not the precedence of *,/ is same > precedence of + operator // & associativity of *,/,+ is from left to right so, y=20/5+5 y=4+5 = 9 & x=5 //so x+y is 14 //hope u got it now ☺
14th Jan 2018, 8:08 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 1
Thank you 😍
14th Jan 2018, 8:37 AM
Tien Dat Dang
Tien Dat Dang - avatar