Answer to Question #140360 in C++ for Rajan Sanger

Question #140360
  1. If I change x++ in the code above to ++x, will this change make any difference? 
  2. Write the steps of executing the statement: x = a++ + (b += x + y);
1
Expert's answer
2020-10-25T19:40:02-0400
1) 
#include <iostream>

int main() {

    int x=5;
    
    std::cout << "In ++X, first increment then print="<<++x;
    std::cout << "So it is called pre increment.\n \n";
    std::cout << "In X++, first print then incrment"<<x++;
    std::cout << "So it is called post increment";
    return 0;
}

2) #include <iostream>

int main() {

    int a,b,x,y;
    a=4;
    x=2;
    y=3;
    x = a++ +(b+=x+y);
    std::cout << "The result of the above terms will be="<<x;
   
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog