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.
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
Post a Comment