title: Why is int foo() an rvalue, while int& foo() is an lvalue in this example?
body: <p>We have the following code example:</p>
  
  <pre><code>// lvalues:
    //
    int i = 42;
    i = 43; // ok, i is an lvalue
    int* p = &amp;i; // ok, i is an lvalue
    int&amp; foo();
    foo() = 42; // ok, foo() is an lvalue
    int* p1 = &amp;foo(); // ok, foo() is an lvalue
  
  // rvalues:
    //
    int foobar();
    int j = 0;
    j = foobar(); // ok, foobar() is an rvalue
    int* p2 = &amp;foobar(); // error, cannot take the address of an rvalue
    j = 42; // ok, 42 is an rvalue
  </code></pre>
  
  <p>I'm trying to understand why does a plain function definition as this:</p>
  
  <pre><code>int foobar();
  </code></pre>
  
  <p>is supposed to be an rvalue, while the same function but with an object reference as the return type, as this:</p>
  
  <pre><code>int&amp; foobar();
  </code></pre>
  
  <p>is an lvalue. (The second part somehow comes naturally, because we specifically ask for and thus keep a reference when defining the function. However, the first example is hard to grasp for me, as I was expecting that the memory location of a function is somehow implicitly deducted, based on the assumption -that might be wrong-, that each function has its own, non changeable location in memory and, in conclusion, the first example should have also been an lvalue reference). Please try and explain this aspect, first.</p>
  
  <p>I understand that: </p>
  
  <blockquote>
    <p>An lvalue is an expression that refers to a memory location and allows us to take the address of that memory location via the &amp; operator. An rvalue is an expression that is not an lvalue.</p>
  </blockquote>
  
  <p>However, as stated above, I'm mostly interested in how functions, as opposed to or in correlation to simple objects, are treated regarding the lvalue/rvalue concept.</p>
  
  <p>Thank you!</p>