4
What happens is this, within the function ins_ult()
I can change the value of root->data
, but outside the function the value remains NULL
.
I’m passing the parameter the wrong way or using the 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);
}
}