i made a function to create a node in linked list which takes a integer as argument ,my program is running fine when i am using this function but my doubt is in malloc used here
What I have tried:
my structure is
struct{
int data;
struct node*}
this is my insert function
void insert(int x){
struct node *temp=(struct node*)malloc(sizeof(struct node));
temp->data=x;
temp->next=head;
head=temp;
}
note i declared head as a global variable as
struct node* head;
clearly head is a pointer variable(pointer to struct node) which will take only 4 bytes
in memory whereas (struct node) will take 8 bytes in memory
my doubt is this when i am using head in sizeof operator instead of struct node that is
struct node *temp=(struct node*)malloc(sizeof(head));
i am getting no error
no warning and getting the exact answer as was before but memory allocation will be different for head(4bytes) and struct node(8 bytes) it should affect my program??