Advertisement
Guest User

Untitled

a guest
Aug 29th, 2015
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #include <stdio.h>
  2. //Defining a structure of the node
  3. struct node {
  4. int data;
  5. struct node* next;
  6. };
  7.  
  8. void insert (struct node* rec, int x) {
  9. struct node* temp = (struct node*)malloc(sizeof(struct node));
  10. temp->data = x;
  11. temp->next = NULL;
  12. rec = temp; // head and rec is now pointing to the same node
  13. }
  14.  
  15. void print(struct node* rec){
  16. printf("%d", rec->data); //error occurs here
  17. puts("");
  18. }
  19.  
  20. main(){
  21. struct node *head = NULL; //head is currently pointing to NULL
  22. insert (head, 5); //Passing the head pointer and integer 5 to insert()
  23. print(head);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement