+ 6
What's difference between $i++ and ++$i
If any code $i=4 $j=$i++ and $j=++$i.what is the value of $j on both questions.I don't understand this
4 ответов
+ 8
$i++ is known as post-increment. It increments the value of $i only after assigning the original value of $i to $j first.
++$i is known as pre-increment. It increments the value of $i before assigning the value to $j, so the updated value of $i will be assigned to $j.
Hence,
$i = 4;
$j = $i++;
// Now, $i = 5 and $j = 4
$i = 4;
$j = ++$i;
// Now, $i = 5 and $j = 5
These theories apply in a similar manner for decrementing as well.
Hope this helps!
+ 5
Thanks
+ 3
Yes, corrected.. thanks for pointing out!
+ 2
Shouldn’t the last one be pre instead of post again