Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- //Defining a structure of the node
- struct node {
- int data;
- struct node* next;
- };
- void insert (struct node* rec, int x) {
- struct node* temp = (struct node*)malloc(sizeof(struct node));
- temp->data = x;
- temp->next = NULL;
- rec = temp; // head and rec is now pointing to the same node
- }
- void print(struct node* rec){
- printf("%d", rec->data); //error occurs here
- puts("");
- }
- main(){
- struct node *head = NULL; //head is currently pointing to NULL
- insert (head, 5); //Passing the head pointer and integer 5 to insert()
- print(head);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement