[Solved] Basic C pointer syntax [closed]


* is both a binary and a unary operator in C and it means different things in different context.

Based on the code you have provided:

*leaf = (struct node*) malloc( sizeof( struct node ) );

Here the void * (void pointer) that malloc returns is being casted to a pointer to struct node, I don’t recommend this, for more information read this

I can guess if you see the declaration of leaf it will be like this:

struct node ** leaf; //declares a pointer to a pointer of struct node

leaf = malloc(sizeof(struct node *) ); //allocate enough memory for pointer
//remember to not cast malloc in C

At this point *leaf is the pointer to struct node where the * is acting as a dereference operator.

1

solved Basic C pointer syntax [closed]