C++ Post-Increment and Compound Assignment Question

Question

Write a program that

  • defines an int variable called x with a value of 123,
  • post-increments that value in the next statement, and
  • adds the value of 20 in the following statement using the compound assignment operator.
  • print out the value afterward.

You can use the following code structure.

#include <iostream> 

int main() 
{ 
    //your code here
}


#include <iostream> 

int main() 
{ 
    int x = 123; 
    x++; 
    x += 20; 
    std::cout << "The result is: " << x; 
} 



PreviousNext

Related