+ 2

Explain the output of the code?

#include <iostream> using namespace std; int main () { int x, y; x = 5; y = ++x * ++x; cout << x << y; x = 5; y = x++ * ++x; cout << x << y; return 0; }

17th Aug 2018, 2:33 PM
Pragyanshu Sharma
Pragyanshu Sharma - avatar
1 Answer
+ 5
IN PREFIX ++x FIRST x IS INCREMENTED AND THAN EVALUATION TAKE PLACE. IN POSTFIX x++ FIRST EVALUATION IS DONE AND THAN ITS VALUE IS INCREMENTED. Decrement goes same way. Small example x = x + x++ + ++x + x =4 + 4(post increment now x=5) + 6(pre increment) + 6. =20. Hope this will help you understand your codeâ˜șâ˜ș.
17th Aug 2018, 3:47 PM
Meet Mehta
Meet Mehta - avatar