+ 3
Doubt
Someone pls explain how this comes...?? int x,y,z; x=2; y=5; z=x+++y; printf("%d %d %d",x,y,z); output: 3 5 7
6 Respuestas
+ 9
The line z= x+++y; is evaluated as
z=x++ + y;
where :
x++ is post increment of x , so its value changes only after the sum of x+y is evaluated.
This is equivalent to:
x=2;
y=5;
z=x+y;
x=x+1;
+ 8
At very first the addition is performed and then X is updated to 3 (X++) before updating X ,Z is assigned 7 .And that's all .🤗
+ 6
See this article: https://www.sololearn.com/learn/Java/2141/
Z gets the value of x+y (2+5=7), and the x++ increments the value of x, making it 3.
Fun fact: doing z=++x+y; would return 8, as it does the calculation before the assignment. Link explains it better.
+ 2
ok friends.....i understood what it is.......
+ 1
btw. some examples of post and pre increment a here :-)
https://code.sololearn.com/ceYh2erq9U7y/?ref=app
+ 1
left to right so it is considers x++ +y
since it is post increment at the time it will be 2, then incremented to 3
z=2++ +5 gives 7
so x get incremented to 3;
hence result 3 5 7