0

++5 & 5++ java answer?

++5 & 5++ java answer?

27th Jul 2023, 10:11 PM
H.V.A CT Dilshan
H.V.A CT Dilshan - avatar
5 odpowiedzi
+ 5
++5 & 5++ java question? Ask a complete and clear question in order to get a complete and clear answer.
27th Jul 2023, 10:30 PM
Lisa
Lisa - avatar
+ 4
You ask post increment and pre increment operator if you have done this topic then practice on sololearn playground otherwise do that topic.
28th Jul 2023, 4:12 AM
Sakshi [Offline 🙃]
Sakshi [Offline 🙃] - avatar
+ 3
This question is popular in the programming world. Personally, I think if you're a slow learner, you need a lot of test cases to understand how both of these statement works but for the discuss sake, I'll be giving you some explanation ++5 will return 6 to where it is called while 5++ will return 5 to where it is called. To explain this better int x = 5; int y = 5; int a = ++x; At this point, a is 6 and x is also 6 int b = y++; at this point, b is 5 and y is 5. But subsequent call to y will be 6 cout << y // 6 cout << b // 5 cout << a // 6 cout << x // 6 You really need many examples to understand this weird incrementation behavior. Knowing it dearly is like knowing 20% of programming
28th Jul 2023, 10:08 PM
RuntimeTerror
RuntimeTerror - avatar
+ 2
error will occur System.out.print(++5); //error int x = 0 //pre-increment System.out.print(++x); //1 System.out.print(x); //1 --------- System.out.print(5++); //error int y = 0 //post-increment System.out.print(y++); //0 System.out.print(y); //1
28th Jul 2023, 4:29 PM
A͢J
A͢J - avatar
+ 1
int a=5, b=5; System.out.println( ++a & b++ ); // 4 ++a is 6 a & b is 4 because binary: 110 6 & 101 5 ------- 100 4 ++ at the end is irrelevant for expression, but b is 6 then
29th Jul 2023, 12:55 PM
zemiak