C++ lvalue vs rvalue

Srecko Kostic
2 min readSep 22, 2022

The C++ lvalue vs. rvalue. Explanation with analogy and source code.

The C++ lvalue vs. rvalue source code
The C++ lvalue vs. rvalue source code

Analogy

A group of thieves wants to rob a bank.

Let’s say the bank is in Florida. The bank address is Florida, Feather Sound, 4837 Maryland Avenue.

A group of thieves goes there, takes all the money, and gets away.

While they are running away, a bag of cash falls on their truck.

No one knows where that bag came from, not even them.

But they do have that bag with money. In order words, they own it.

After their theft, I ask you to visit the bank and pick up some money for me.

When you get to the bank, your response will be something like this.

Hey, that bank got robbed. There is no money in there.

However, we don’t know about the bag that fell from the sky. The one thieves own.

The bag is anonymous because we can’t identify it. We can’t determine its origin.

The bank is an analogy for lvalue. We can identify the bank using the address.

The lvalue is something that we can identify through an address.

The bank at that address doesn’t have money anymore. Thieves stole it.

The bag that fell from the sky is an analogy for rvalue. We can’t identify it.

The bag with the cash is an anonymous resource.

Code

The C++ lvalue vs. rvalue source code

--

--

Srecko Kostic

I create content from my perspective on topics I learn. Some information may be incorrect, but I hope some find my content useful.