#include <stdio.h>
#include <stdlib.h>
typedef struct node* Node;
struct node{
int a;
struct node* next;
};
void insertAtBeginning(Node head){
Node temp = malloc(sizeof(struct node));
temp->a = 10;
temp->next = head;
head = temp;
}
int main(){
Node one = malloc(sizeof(struct node));
one->a = 11;
Node head = one;
insertAtBeginning(head);
printf("%d",head->a);
}
Expected : 10
Received : 11
I'm passing pointer(struct node* head) to function why is it not reflecting back in main method?
typedef(i.e. yourNode), except possibly in very special circumstances. Disguising the number of levels of indirection is confusing, much more than expressing object pointer types explicitly creates any kind of trouble.