+ 1
I don't get why the output of these are different !
Whiteout any ++ on num the output should be 4 and 7 Ű with prefix ++sum it should be 5 and 9 cause it add one to the sum+3 ,but why with post fix the output become 4 and 8 it didn't add one to first one but added to second https://code.sololearn.com/c3xvm02cVoOP/?ref=ap
4 RĂ©ponses
+ 1
int num = 1;
num += 3 // num = 4
cout << num++ ; //prints 4 but num is incremented by 1 so num = 5
num +=3 //num = 8
cout << num++ ; //prints 8 and num = 9
+ 2
Careful, post and pre increments. num++ prints the value FIRST then adds one to it. ++num adds one to the value and THEN prints it.
+ 1
++num : increments first and returns 'new' value
num++ : increments after and returns 'old' value
+ 1
Thanks â€â€