Thing you did here is called an undefined behavior. Basically it's a situation where program doesn't know which action out of many should go first. In this case it's whether to increment i variable or to first add it up to x variable.
Generally speaking it's hard to predict what the outcome will be in this type of situations. Just avoid using multiple increments of the same variable in one equation and you should be good.