dereferencing a pointer when passing by reference

前端 未结 3 1358
忘了有多久
忘了有多久 2020-12-02 15:46

what happens when you dereference a pointer when passing by reference to a function?

Here is a simple example

int& returnSame( int &example )         


        
3条回答
  •  爱一瞬间的悲伤
    2020-12-02 16:16

    A compiler doesn't "call" anything. It just generates code. Dereferencing a pointer would at the most basic level correspond to some sort of load instruction, but in the present code the compiler can easily optimize this away and just print the value directly, or perhaps shortcut directly to loading inum.

    Concerning your "temporary object": Dereferencing a pointer always gives an lvalue.

    Perhaps there's a more interesting question hidden in your question, though: How does the compiler implement passing function arguments as references?

提交回复
热议问题