What will be the output of the following program?
1 2 |
|
Note: This problem is language agnostic, meaning that it is language independent.
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
This behaviour is well defined and i = i++ works in the following way:
First it evaluates expression i++. Evaluation of this expression produces an expression value (which is the value of i before increment) and increments i.
Later it assigns the expression value to i, overwriting incremented value.
So value of i never increases and thus 0 will be printed indefinitely.