我不想创建通用的*头节点,我想通过引用传递我的数据,但是尽管我为下一个节点创建了新节点,但我无法在main上到达我的新节点。如果我看的是n1,下一步我看到的是null.Why,有什么问题吗?,İ?
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct node{
int data;
struct node* next;
};
void add(struct node** head,int data){
struct node * tmp = *head;
while(tmp != NULL){
tmp = tmp->next;
}
tmp = (struct node*) malloc(sizeof(struct node));
tmp->data= data;
tmp->next=NULL;
}
int main()
{
struct node n1;
n1.data=5;
n1.next=NULL;
add(&(n1.next),15);
printf("%d",n1.next->data);
return 0;
}
https://stackoverflow.com/questions/50768400
复制相似问题