Computer Science, asked by nandinikumariroy2532, 4 months ago

Write the output of the followings
int m = 7, n = 5;
int p = m+ + - + +n + m + --n ;
System.out.println( p);
System.out.println( m);
System.out.println( n);

Answers

Answered by Anonymous
2

We will go from left to right step-by-step:

Remember that prefix increment/decrement changes the value in the variable and returns it while postfix increment/decrement changes the value in the variable but does not return the value to the expression.

m=7, n=5

p=m++ - ++n + m + --n

So, p=7 - ++n +m + --n  (m=8, n=5)

p= 7 - 6 + m + --n  (m=8,n=6)

p= 7 - 6 + 8 + --n (m=8, n=6)

p= 7 - 6 + 8 + 5 (m=8, n=5)

p= 7 - 6 +13

p=20-6

p= 14

Output:

14

8

5

Similar questions