Question: ```
class C
{
public:
    int True(int i) const
    {
        return i+2;
    }
};

const C& F(const C& c)
{
    return c;
}

int main()
{ 
    const C& c = F(C());                             // Line 1
    cout << boolalpha << c.True(1) << endl;          // Line 2
}

```

Question> why the above code can print the value correct?
I assume the variable `c` will refer to an invalid temporary `C` object when it hits line 2.

// Update

I would like to update this OP to illustrate the reason why I am concern on this question.

Here is code snippet from C++ Templates: The Complete Guide

```
// maximum of two values of any type 
template <typename T> 
inline T const& max (T const& a, T const& b) 
{ 
    return a < b ? b : a; 
} 

```

As you can see the function return reference to the pass-in parameter.
I just wonder why not the following version instead:

```
// maximum of two values of any type 
template <typename T> 
inline T max (T const& a, T const& b) 
{ 
    return a < b ? b : a; 
} 

```

Answer: 
Paragraph 12.2/4 of the C++11 Standard specifies that *in some situations* the lifetime of temporaries can indeed be extended beyond the end of the full expression in which they are generated:

> 
> There are **two contexts** in which temporaries are destroyed at a different point than the end of the full expression. [...]
> 
> 
> 

The first context is not relevant. However, per Paragraph 12.2/5:

> 
> The second context is when a reference is bound to a temporary. **The temporary to which the reference is bound** or the temporary that is the complete object of a subobject to which the reference is bound **persists for the lifetime of the reference *except***:
> 
> 
> — A temporary bound to a reference member in a constructor’s ctor-initializer (12.6.2) persists until the constructor exits.
> 
> 
> — **A temporary bound to a reference parameter in a function call (5.2.2) persists until the completion of the full-expression containing the call.**
> 
> 
> — The lifetime of a temporary bound to the returned value in a function return statement (6.6.3) is not extended; the temporary is destroyed at the end of the full-expression in the return statement.
> 
> 
> — A temporary bound to a reference in a new-initializer (5.3.4) persists until the completion of the full-expression containing the new-initializer.
> 
> 
> 

Here, the temporary constructed with `C()` is bound to the argument `c` of function `F`. Therefore, the temporary is destroyed at the end of the full-expression which contains the call to function `F()`, and the returned reference is *dangling*.

Invoking function `True()` on it causes **Undefined Behavior**.
This invokes undefined behaviour. As soon as the full expression involving `F(C())` completes, the temporary created by `C()` is destroyed, so the reference returned by `F` is no longer valid. 

However, undefined behaviour does not guarantee your program will crash. In more annoying cases (like this) it simply causes subtle, hard to diagnose bugs. As for why this undefined behaviour gives you this specific result, I refer you to this [famous answer](https://stackoverflow.com/questions/6441218/can-a-local-variables-memory-be-accessed-outside-its-scope/6445794#6445794).