1

after figuring out, how the linked lists stuff works in C I was just wondering how to correctly allocate a new node.

So lets say my linkedlist is defined with the following struct:

typdef struct NewNode
{
  int data;
  struct node *next;
} Node;

Now I'm going to create a new temporary node for whatever reason:

node *temp = (node*) malloc(sizeof(node);

Do I need the cast (node*) or can I as I've seen in couple tutorials leave this without the casting. If not can you tell me what possible errors could occur as my implementation without the casting is completly working.

node *temp = malloc(sizeof(node);
Richie
  • 73
  • 1
  • 6

0 Answers0