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

Trace Lvalue and Rvalue Function Overloads

hardTemplates

📄 Code

Read carefully — what does this print?
1#include <iostream>
2 
3template <typename T>
4void identify(T& value) {
5 std::cout << "Lvalue: " << value << "\n";
6}
7 
8template <typename T>
9void identify(T&& value) {
10 std::cout << "Rvalue: " << value << "\n";
11}
12 
13int main() {
14 int x = 5;
15 identify(x);
16 identify(10);
17 identify(x + 3);
18 identify(x += 2);
19 identify(++x);
20 identify(x++);
21 std::cout << "x = " << x << "\n";
22 return 0;
23}

🎯 Your Answer