Re: [問題] 請問call by pointer回傳的問題

看板C_and_CPP作者 (......)時間13年前 (2012/08/22 00:37), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《polomaster27 (polo)》之銘言: : 開發平台(Platform): (Ex: VC++, GCC, Linux, ...) : Dev-C++ : 問題(Question): : void Test( ????? ) : { : Node *temp = NULL; : temp = new Node; : temp->next = NULL; : strcpy( temp->Variable_name, "counter" ) ; : } // end void : int main() : { : Node *Variable_list_head = NULL ; : Test( Variable_list_head ) ; : cout << Variable_list_head << endl; : system("pause") ; : return 0 ; : } // end main() : 請問要怎麼把Variable_list_head指標指向temp的位置? void Test(Node **ptr){ Node *temp=NULL; temp=new Node; temp->link=NULL; (*ptr)=temp; strcpy( temp->Variable_name, "counter" ); } int main(){ Node *Variable_list_head = NULL ; Test( &Variable_list_head ) ; cout << Variable_list_head << endl; system("pause") ; return 0 ; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.252.241.128
文章代碼(AID): #1GCxbAj9 (C_and_CPP)
文章代碼(AID): #1GCxbAj9 (C_and_CPP)