+ 3
increment operator
int main() { int i=5; cout<<(++i + i++); } what's its value and why
7 odpowiedzi
+ 2
actually output is 13. compile and check
+ 2
the output is 13 because first ++i so value in incresing by 6 and after i it's new value allocated 6 and after i++ new value of i is 7 and addition of two value 6+7=13
+ 1
answer is different in dev c++ and visual studio
+ 1
ya it'll be 13
+ 1
Try avoiding using incrementation like that. The answer is 13 (or smt else depending with what you compile it) becouse compilator deosn't provide safety of in which order incrementation is done.
If you separate them like
i = 5
sum = ++i
sum += i++
Sum is 12
0
ok i tried out instead of a + i used << to see the single nummbers
cout<<++i<<i++;
and that outputs: 66
so normaly it has to be 12 if you add those
0
There are two types of incrementations you should know about, postfix e.g ++1 and prefix e.g I++