April 21st, 2006

Coffee Transporter

Coder geeks

This question was sent out at work by a co-worker:
Solve this in your head: What does the following code display, and why?

$i = 1;
$i += $i++ + ++$i;
echo 'i=', $i;

Bonus question: Is the result always the same in other programming languages (JavaScript, Java, C#, ...; provided the syntax is adapted to the host language :))? Why (not)?

Collapse )