+ 3

increment operator

int main() { int i=5; cout<<(++i + i++); } what's its value and why

7th Aug 2016, 7:13 AM
Aditya Singh
Aditya Singh - avatar
7 Respuestas
+ 2
actually output is 13. compile and check
7th Aug 2016, 7:29 AM
Aditya Singh
Aditya Singh - avatar
+ 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
7th Aug 2016, 5:14 PM
rahul lunagariya
rahul lunagariya - avatar
+ 1
answer is different in dev c++ and visual studio
7th Aug 2016, 8:46 AM
Hooman
Hooman - avatar
+ 1
ya it'll be 13
7th Aug 2016, 10:14 AM
Pradeep Gupta
Pradeep Gupta - avatar
+ 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
9th Aug 2016, 12:11 AM
Maciej Falbogowski
Maciej Falbogowski - avatar
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
7th Aug 2016, 7:48 AM
Jackson Seba
Jackson Seba - avatar
0
There are two types of incrementations you should know about, postfix e.g ++1 and prefix e.g I++
21st Aug 2016, 9:19 PM
Jeffrey Kola Abodunde