September 9th, 2013, 12:40 AM
Join Date: Jan 2013
Time spent in forums: 1 Day 45 m 46 sec
Reputation Power: 1
Explain please, increment
int a=5+ i++;
this is my simulation:
int i=1; // i initialized to 1
int a=5+ i++; // i++ is post-increment, therefore, 5+1=6
int b=a*++i; // value of a which is 6 transferred to b, then ++i is pre increment, therefore the value is 2, 6*2=12
when i run the program, the answer is: 18
my question is how did ++i in int b became 3 when it was initialized to value 1, shouldn't that be 2 instead?
Last edited by Kuiva : September 9th, 2013 at 01:24 AM.
Reason: correction by SALEM, i interchanged post and pre increment