Please can someone help me explain this code with the output as follows... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Please can someone help me explain this code with the output as follows...

int x=5,y=5; cout<<x<<" "<<y<<endl; cout<<++x<<" "<<--y<<endl;// prefix cout<<x<<" "<<y<<endl; cout<<x++<<" "<<y--<<endl;// postfix cout<<x<<" "<<y<<endl; output5 56 46 46 47 3

12th Jun 2016, 5:29 PM
Peters Chikezie
Peters Chikezie - avatar
4 Answers
+ 6
cout<<x<<" "<<y<<endl; //prints 5 5 cout<<++x<<" "<<--y<<endl; // adds 1 to x and sub 1from y prints 6 4 cout<<x<<" "<<y<<endl; // displays the latest updated values of x and y prints 6 4 cout<<x++<<" "<<y--<<endl; // first displays the current value and then updates values of x and y // prints 6 4 which were the current values // adds 1 to x and sub 1 from y after displaying // current values i.e 6 4 cout<<x<<" "<<y<<endl; // prints 7 and 3 which were updated in the previous line after printing 6 and 4 /* Hope this helps :) */ comments are a little off ... hard for me to edit from my mobile phone
12th Jun 2016, 5:55 PM
Satan 666
Satan 666 - avatar
0
thank you. it's very helpful.
12th Jun 2016, 6:03 PM
Peters Chikezie
Peters Chikezie - avatar
0
There is a rule that expalin that a variable can not be upadated twice in an expression. if such things happen the result depends upon the implementation of that specific compiler .
20th Jun 2016, 1:13 AM
Utpal Kumar
Utpal Kumar - avatar
0
Please this program is not is not working
17th Aug 2016, 9:28 PM
Ekele Joshua
Ekele Joshua - avatar