<分区>
我在用 C 语言初始化节点值以传递指针时遇到问题,
我已经写了类似 follow 的东西,
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node *next;
};
void add(struct node *head, int val){
struct node *n1 = NULL;
n1 = (struct node *)malloc(sizeof(struct node ));
n1 -> data = val;
n1 -> next = NULL;
if(head == NULL){
head = n1;
printf("Head2 is initialized");
return;
}
}
int main(){
struct node *ptr = NULL;
struct node *temp;
add(ptr, 11);
printf("\nData = %d", ptr->data);
return 0;
}
你能告诉我这段代码有什么问题吗,
当我执行
printf("\nData = %d", ptr->data);
系统显示 Windows 已停止工作
谢谢