0
a=2 b=a++ b= ? (why 2)😠😠
6 odpowiedzi
+ 6
the answer is 'b=2' because first the value of 'a' is assigned to the variable 'b' then it is incremented. since at the time of assignment its value is 2 so result is "b=2"
+ 2
where is the code?
+ 2
it is important to understand the order of operations with the increment operator.
There are 2 versions of the increment operator:
$a++
++$a
there's one important a subtle difference between them.
$a++ executes the increment LAST inside the line of code.
++$a executes the increment FIRST inside the line of code.
example:
$a = 5
print($a++) // prints 5 since increment executes after print.
print($a) // prints 6
print (++$a) // prints 7 since increment executes before print.
+ 1
operators Module 3 quiz 3 Th question
- 1
b=3
- 3
$b=++$a