0

About Java McQ

How print(++x = x++) is false It should be the same result? Doesn’t it?

26th Nov 2022, 7:21 AM
Mustakim Rahman
Mustakim Rahman - avatar
7 Answers
+ 3
No, assuming <x> is a number, ++x doesn't equal x++ because these operators have different way of working ++x increments in-place (immediately) x++ increments after the current line has been evaluated by Java compiler For less confusion in reading a code, it is NOT recommended to mix the use of these operators in a single line of code, the code looks more of a riddle than an actual code when it's being written that way.
26th Nov 2022, 8:01 AM
Ipang
+ 3
Mustakim Rahman int x = 7 x++ == ++x; In this case result would false because of (x++) x++ = 7 but after increment x would be 8 but ++x here is preincrement so ++x = 9 because x was already 8
26th Nov 2022, 10:41 AM
A͢J
A͢J - avatar
+ 2
Mustakim Rahman int x = 7; ++x = 8 and x++ = 7; but in this case ++x == x++;. after increment of x (++x) , x++ would be 8 so 8 == 8 true System.out.println (++x==x++) = true
26th Nov 2022, 10:34 AM
A͢J
A͢J - avatar
+ 2
Thanks Ipang A͢J for removing confusion!❤️‍🔥
26th Nov 2022, 11:22 AM
Mustakim Rahman
Mustakim Rahman - avatar
+ 1
Yes brother i just forget to text properly, (++x == ++x) … Sometimes in the mcq part wrong answere are the correct answere. Very Frustrating!
26th Nov 2022, 7:50 AM
Mustakim Rahman
Mustakim Rahman - avatar
+ 1
Ipang Suppose int x=7; x++; or ++x; What would be the output? 7 or 8?
26th Nov 2022, 8:49 AM
Mustakim Rahman
Mustakim Rahman - avatar
0
Mustakim Rahman Paste this inside a class' main method, I think you'll understand the difference afterwards int x = 7; System.out.println("x++ = " + x++); System.out.println("After line evaluation <x> = " + x); x = 7; // reset <x> value to start over System.out.println("\n++x = " + ++x); System.out.println("After line evaluation <x> = " + x);
26th Nov 2022, 9:32 AM
Ipang