Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • 2
    A reference is a reference to l-value, not necessarily to a variable. Because of that, it's much closer to a pointer than to a real alias (a compile-time construct). Examples of expressions that can be referenced are *p or even *p++ Commented Mar 2, 2009 at 16:27
  • 6
    Right, I was just pointing the fact that a reference may not always push a new variable on the stack the way a new pointer will. Commented Mar 3, 2009 at 20:36
  • 4
    @VincentRobert: It will act the same as a pointer... if the function is inlined, both reference and pointer will be optimized away. If there's a function call, the address of the object will need to be passed to the function. Commented Feb 13, 2012 at 23:08
  • 1
    int *p = NULL; int &r=*p; reference pointing to NULL; if(r){} -> boOm ;) Commented Oct 4, 2015 at 12:37
  • 2
    This focus on the compile stage seems nice, until you remember that references can be passed around at runtime, at which point static aliasing goes out of the window. (And then, references are usually implemented as pointers, but the standard doesn't require this method.) Commented Oct 11, 2015 at 17:35