title: How do I insert a node at the beginning of a linked list?
body: <p>What is wrong with <code>addAtBegin</code>? The list seems to be correct after assigning the newly created <code>node</code> to <code>start</code>, but when control returns to <code>main</code>, the new value is not saved.</p>
  
  <pre><code>typedef struct node
  {
      int data;
      struct node *link;
  }node;
  
  node* createList(int data)
  {
      node *tempNode=(node*)malloc(sizeof(node));
      tempNode-&gt;data=data;
      tempNode-&gt;link=NULL;
      return tempNode;
  }
  
  void addAtBegin(node *start,int data)
  {
      node *addedNode=(node *)malloc(sizeof(node));
      addedNode-&gt;data=data;
      addedNode-&gt;link=(start==NULL)?NULL:start;
      start=addedNode;
  }
  
  void displayNodes(node *start)
  {
      node *startCopy=start;
      while(startCopy!=NULL)
      {
          printf("%d\t",startCopy-&gt;data);
          startCopy=startCopy-&gt;link;
      }
      printf("\n");
  }
  
  int main( )
  {   
      node *start=createList(2);
      addAtBegin(start,1);
      displayNodes(start);
      return 0;
  }
  </code></pre>