【发布时间】:2013-10-28 14:01:19
【问题描述】:
我在一个函数中有一个指针,我想返回该指针,以便稍后修改它指向的内容。返回它会返回指针指向的地址还是指针本身?这个问题是因为我想更改链表的头部指向的内容。
例如
struct node_{
//variables
}*headPtr=NULL; //assume when we are returning headPtr in foo() it is no longer NULL but points to something
typdef struct node_ node;
node foo(){
//some if conditions
return headPtr;
}
main(){
node *tmpPtr;
tmpPtr=foo();
}
【问题讨论】:
-
您在
//some if conditions中获得了什么?我想你需要使用malloc()
标签: c pointers memory linked-list