typedef struct node{
int data;
struct node* next;
}ListNode;
void init(ListNode **head){
(*head) = (ListNode *)malloc(sizeof(ListNode));
(*head)->next = 0;
}
ListNode* another_init(){
ListNode *head = (ListNode *)malloc(sizeof(ListNode));
return head;
}
我有一些问题:2种初始化链表的方法,它们是否相等?
1.in功能初始化,为什么我应该把第二级指针?
2.函数init与another_init相同吗?
好吧,首先,'another_init'错过了将'0'分配给'next'。 –
可能重复[传递数组,在C中int指针](http://stackoverflow.com/questions/4916716/passing-arrays-pointers-to-int-in-c) – 2013-08-07 11:36:56
这:^^因为在C中,参数按值传递(“复制”)。 – 2013-08-07 11:37:16