What does int & mean

后端 未结 6 775
隐瞒了意图╮
隐瞒了意图╮ 2020-12-12 15:39

A C++ question,

I know

int* foo(void)

foo will return a pointer to int type

how about

int &foo(void)
         


        
6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-12 16:18

    just playing with variables to show you the meaning

    int i = 5;
    int * pI = &i;
    int & referenceToI = * pI;
    referenceToI = 4; // now i == 4
    

    EDIT: References are just a syntactic sugar for easier pointers handling. at the assembly level, the code generated by the compiler returns to a you an address-pointer

提交回复
热议问题