CPPForSchool.com: Variable, Operator & Expression Set 2: Assignment 7

7.  What is the output of following program?

Once again, I am being tested on my comprehension of order of operations and mathematics within C++.  Below is a screen shot each question.


Order of left to right.

int x = 10, y;
y = x++;
cout << y;

Answer: 10  

int x = 10, y;
y = x++;
cout << x;

Answer: 11


int x = 10;
x++;
cout << x;

Answer: 11

int x = 10, y;
y = ++x;
cout << y;

Answer: 11

int x = 10;
cout << ++x;

Answer: 11

int x = 10;
cout << x++;

Answer: 10


For the sake of continuity, I have included the "Show the answer" screenshot, followed by the source and output for each problem.





















Comments

Popular posts from this blog

CPPForSchool.com: Variable, Operator & Expression Set 1: Assignment 9

CPPForSchool.com: Array - Single Dimension Set 1 Assignment 6

CPPForSchool.com: Variable, Operator & Expression Set 1: Assignment 8