DEV Community

Single Linked List Using C

Orion on December 13, 2020

#include<stdio.h> #include<stdlib.h> typedef struct Node { int data; struct Node *next; }node; node *HEAD=NULL; //Interface...
Collapse
 
ac000 profile image
Andrew Clayton

In C, you shouldn't cast the return value from malloc(3) et al.

Collapse
 
0orion0 profile image
Orion

Why ?

Collapse
 
ac000 profile image
Andrew Clayton

In C (and we're talking about C and not C++)

1) It's superfluous.
2) Can hide bugs depending upon architecture/compiler etc, where if you don't

#include <stdlib.h>
Enter fullscreen mode Exit fullscreen mode

the return type of malloc may be assumed to be int which may mean you're using a truncated address and that won't end well...