Working with unary minus op. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Working with unary minus op.

hey guys, which way is this evaluated please? // unary minus operators int i= 5,j=2,k=3; int l = i * - (j+k); //l = 5-*5 is this evaluated right to left? // or. left to right 5*-5? System.out.println(l); //-25

26th Nov 2017, 10:56 AM
D_Stark
D_Stark - avatar
2 Answers
+ 2
left to right, also 5-*5 wouldnt make any sense and even is wrong syntax.
26th Nov 2017, 11:27 AM
Jeremy
Jeremy - avatar
+ 1
It helps to draw the evaluation tree which looks like * / \ i - \ + / \ j k
26th Nov 2017, 6:30 PM
Weazel