Skip to main content
Engineering LibreTexts

4.7: L Value and R Value

  • Page ID
    29039
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    What am L (or R) Value?

    They refer to on the left and right side of the assignment operator. The Lvalue (pronounced: L value) concept refers to the requirement that the operand on the left side of the assignment operator is modifiable, usually a variable. Rvalue concept pulls or fetches the value of the expression or operand on the right side of the assignment operator. Some examples:

    int age;    //variable set up
    // then later in the program
    age = 39;

    The value 39 is pulled or fetched (Rvalue) and stored into the variable named age (Lvalue); destroying the value previously stored in the age variable.

    int age;    //variable set up   
    int voting_age = 18;    // variable set up with initialization
    // then later in the program
    age = voting_age;
    

    If the expression has a variable or named constant on the right side of the assignment operator, it would pull or fetch the value stored in the variable or constant. The value 18 is pulled or fetched from the variable named voting_age and stored into the variable named age.

    age < 17;

    If the expression is a test expression or Boolean expression, the concept is still an Rvalue one. The value in the identifier named age is pulled or fetched and used in the relational comparison of less than.

    const int JACK_BENNYS_AGE = 39; // constant set up
    // then later in the program
    JACK_BENNYS_AGE = 65;
    

    This is illegal because the identifier JACK_BENNYS_AGE does not have Lvalue properties. It is not a modifiable data object, because it is a constant.

    Definitions

    LValue
    The requirement that the operand on the left side of the assignment operator is modifiable, usually a variable.
    RValue
    Pulls or fetches the value stored in a variable or constant.

    Adapted from: "Lvalue and Rvalue" by Kenneth Leroy Busbee, (Download for free at http://cnx.org/contents/303800f3-07f...93e8948c5@22.2) is licensed under CC BY 4.0


    This page titled 4.7: L Value and R Value is shared under a CC BY-SA license and was authored, remixed, and/or curated by Patrick McClanahan.