I am having problem while initializing the node value to passed pointer in C language,
I have written something like 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;
}
Could you please tell me what is the issue in this code,
When i execute
printf("\nData = %d", ptr->data);
System shows Windows has stopped working
Thanks
 
     
    