+ 1

Could someone provide explaination regarding the working of increment and decrement operations esp. explain the working of below

int a=1; cout<<++a+a++<<endl; //Output is 5 a=1; cout<<(a++)+(++a)<<endl; //Output is 4 a=1; int b=++a + ++a + ++a; cout<<b; //Output is 10 *Please note that the outputs are as received from Dev C++ Compiler Thank You.

30th Mar 2019, 8:53 PM
Aravind Kannan Rathinasabapathi
Aravind Kannan Rathinasabapathi - avatar
2 Antworten
+ 2
int a=1; cout<< ++a + a++ <<endl //Output is 5 ++a a = 2 2 + a++ 2 + 2 ++ 2 + 2 + 1 5 a=1; cout<<(a++)+(++a)<<endl; //Output is 4 (a++) = (1)++ | (a++) = 1 but after this variable is now 2 here \/ 1 + (++a) this one has the increment during so ++a = 3 1 + 3 = 4 Try to understand the third one now I think you got it!
30th Mar 2019, 10:05 PM
Bruno Costa
Bruno Costa - avatar