CPPForSchool.com: Variable, Operator & Expression Set 2: Assignment 8
8.
What is the output of following program?
int x = 10,y;
y = x + x++;
cout << y;
Answer: 21
int x = 10,y;
y = ++x + x++ + x;
cout << y;
Answer: 31
int x = 10, y;
y = x++ + x + ++x;
cout << y;
Answer: 33
In order to truly confirm the output of each of these, I have compiled each one accordingly. Below is the source and output.
int x = 10,y;
y = x + x++;
cout << y;
Answer: 21
int x = 10,y;
y = ++x + x++ + x;
cout << y;
Answer: 31
int x = 10, y;
y = x++ + x + ++x;
cout << y;
Answer: 33
In order to truly confirm the output of each of these, I have compiled each one accordingly. Below is the source and output.
Comments
Post a Comment