I'm trying to understand why I sometimes see brackets containing a data type on the right hand side of an assignment operator in C.
Specifically I was trying to implement a linked list and because I'm still new to C I was using this to guide me.
I came across this line: struct node* link = (struct node*) malloc(sizeof(struct node));
It's part of the instertFirst
function which, I guess, adds a new item to the head of the linked list.
Breaking this line down according to my current understanding it states: create a struct node
pointer called link
that points to a newly allocated chunk of memory that is the size of the node
struct.
What exactly then is the purpose of (struct node*)
? My best guess is that it gives that newly allocated chunk of memory a type...?