+ 11
What is the output of this code? $x=2; $y=++$x; echo $x+$y;
Why the answer is 6
11 Answers
+ 10
Garuda first only value of x is changing due to pre increment and due to assignment of value of x in y. y value to be changed by 3 so both value become 3
+ 14
Garuda hi,
$x = 2;
$y = ++$x;
So $y = 3
$x = 3 due to pre increment the value of x is change to 3 and this 3 is assigned to $y that's what 3+3=6
6 come as output
+ 11
If we used $y=$x++; the answer would be 5.
+ 11
So the true answer 5 or 6?
+ 10
but in my opinion the correct answer is 5, because x=2 and y=x++ so x+y=2+3
+ 10
Value y=3?
And so the value of x changes to 3 too?
+ 10
thank you for your answer DishaAhuja
+ 7
Answer 6
0
salom
- 1
Answer 5