Recently I found that when I'm inserting a node in a linked list(not first of it)
void Insert(Node*head, int index, int data)
{
Node* temp = find(head, index);//this will lead to needed position and check for Null returning
Node* t = (Node*)malloc(sizeof(Node*));
t->data = data;
t->next = temp->next;
temp->next = t;
}
I can malloc like this Node* t = (Node*)malloc(sizeof(Node*))
not like this Node* t = (Node*)malloc(sizeof(Node))
which I had saw almost in every resource code I had read.
when I checked, I was allocating 4 bytes less always but my code still was running well.
which seem confusing to me. How is this possible? or is it the right form and I had it wrong?
I have recently learnt dynamic memory allocation, so I'm sorry if it's a stupid question.