lvalues and rvalues in C++

The first 1000 people who click the link in the description will get 2 free months of Skillshare Premium:

Patreon ►
Instagram ►

Twitter ►
Discord ►

Series Playlist ►

This video is sponsored by Skillshare.

27 thoughts on “lvalues and rvalues in C++

  1. people, don't get confused by c++ standard saying that string literals are lvalues but TheCherno called them rvalues 9:14 , thats because of implicit constructions.
    const char *str = "string"; here "string" is an lvalue.
    but it this line
    std::string str = "string";
    "string" is rvalue, because that code is implicit form of std::string str = std::string("string"), where std::string("string") is rvalue

  2. I am studying compiler design and this came up in the book so that helped me
    There were also two stage mapping where the name points to location and called environment

  3. C string literals are actually the only literal that are lvalues, the following code demonstrates this:

    #include <iostream>

    #include <type_traits>

    int main(int argc, char *argv[])


    std::cout << std::boolalpha << "is l-value: " << (std::is_lvalue_reference<decltype("hello")>::value ? true : false) << std::endl;

    return 0;


    If you run it prints "true".
    I think it should be due to how the compiler stores string literals in order to optimize their use

  4. Cherno: You shouldn't try to find a definition for what l value and r value mean.
    Also Cherno 15 seconds later: left side and right side are a good way to think of them.

  5. Perfect. Fantastic topic. This topic is very tied to move semantics as you already said. C++ is a great language because a programmer can manually do whatever he wants to reduce copying, manipulate with memory, do some optimization but if there is no awareness of that, using c++ has no much sense. It is like you want to clean your bathroom but with no special reason to do that.

    Good job!

Leave a Reply

Your email address will not be published. Required fields are marked *