What happens is the following, inside the ins_ult()
function I can change the value of root->data
, but outside the function the value remains NULL
.
Am I passing the parameter wrongly or using malloc
incorrectly?
#include<stdlib.h>
#include<stdio.h>
typedef struct Node_t{
void *data;
struct Node_t *next;
}Node;
int main(){
Node *root;
root=NULL;
ins_ult(root,100);
printf("%d,%d\n",root->data);
}
void ins_ult(Node *root, void *data){
if(root == NULL){
root = malloc(sizeof(Node));
root->data = data;
root->next = 0;
printf("%d\n",root->data);
}
}