CJCoding With Joseph
15free / daySign inCreate account
← Back to Question List
C++ Code Walkthrough #94

Classify Lvalues and Rvalues

mediumTemplates

📄 Code

Read carefully — what does this print?
1#include <iostream>
2 
3int main() {
4 {
5 int x = 5;
6 int result = x;
7 std::cout << "x: " << result << ", x is now " << x << "\n";
8 }
9 {
10 int x = 5;
11 int result = 10;
12 std::cout << "10: " << result << ", x is now " << x << "\n";
13 }
14 {
15 int x = 5;
16 int result = x + 2;
17 std::cout << "x + 2: " << result << ", x is now " << x << "\n";
18 }
19 {
20 int x = 5;
21 int result = (x += 2);
22 std::cout << "x += 2: " << result << ", x is now " << x << "\n";
23 }
24 {
25 int x = 5;
26 int result = ++x;
27 std::cout << "++x: " << result << ", x is now " << x << "\n";
28 }
29 {
30 int x = 5;
31 int result = x++;
32 std::cout << "x++: " << result << ", x is now " << x << "\n";
33 }
34 return 0;
35}

🎯 Your Answer