I was doing a practice Computer Science UIL test form when I came across this problem:
What is output by the following?
int a = 5;
int b = 7;
int c = 10;
c = b+++-c--+--a;
System.out.println(a + " " + b + " " + c);
I put down the answer "No output due to syntax error" but I got it wrong. The real answer was 4 8 1! (I tested it out myself)
Can someone please explain to me how line 4 works?
Thanks
I added some parentheses:
int a = 5;
int b = 7;
int c = 10;
c = (b++) + (-(c--)) + (--a);
System.out.println(a + " " + b + " " + c);
b++ : b = b + 1 after b is used
c-- : c = c - 1 after c is used
--a : a = a - 1 before a is used
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With