main()は、引数パラメーターFirst Nodeを使用してCall_By_Test()関数を呼び出します。Call_By_Test()で最初のノードを解放しましたが、main()で最初のノードアドレスが解放されません。なぜですか?
typedef struct LinkList{
int data;
struct LinkList *next;
}mynode;
void Call_By_Test(mynode * first)
{
free(first->next);
first->next = (mynode *)NULL;
free(first);
first = (mynode *)NULL;
}
int main()
{
mynode *first;
first = (mynode *)malloc(sizeof(mynode));
first->data = 10;
first->next = (mynode *)NULL;
cout<<"\n first pointer value before free"<<first<<endl;
Call_By_Test(first);
// we freed first pointer in Call_By_Test(), it should be NULL
if(first != NULL)
cout<< " I have freed first NODE in Call-By-Test(), but why first node pointer has the value "<<first<<endl;
}
出力:最初のポインター値0x804b008 Call-By-Test()で最初のNODEを解放しましたが、最初のノードポインターの値が0x804b008である理由