我在一個函數中有一個指針,我想返回那個指針,以便我可以修改它指向以後的內容。將返回它返回指針指向的地址或指針本身?這個問題是因爲我想改變鏈表的頭部所指向的內容。返回一個指針並修改那個指針指向的內容
因此,例如
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();
}
你有什麼'/如果條件'?我猜你需要使用'malloc()' – jev