Passing pointer argument by reference under C?

前端 未结 6 1973
清歌不尽
清歌不尽 2020-12-01 22:20
#include 
#include 

void
getstr(char *&retstr)
{
 char *tmp = (char *)malloc(25);
 strcpy(tmp, \"hello,world\");
 retstr = tmp;
}         


        
6条回答
  •  生来不讨喜
    2020-12-01 22:28

    C lang does not have reference variables but its part of C++ lang.

    The reason of introducing reference is to avoid dangling pointers and pre-checking for pointers nullity.

    You can consider reference as constant pointer i.e. const pointer can only point to data it has been initialized to point.

提交回复
热议问题