+ 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

2 Answers

+ 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 âș

+ 1

Thank you đ