I am newbie to the c programming and am confused with the concepts.
I create a struct c_list. Then I want to assign an int to the struct member id with head->id = 10. However, after using printf function, the output is something like "id value: 85472". Why doesn't it print 10 directly? Where did I do it wrong?
Thanks in advice,
The source is as below.
Code:
#include <stdlib.h>
#include <stdio.h>
struct c_list{
struct c_list *next;
int id;
};
void
init(struct c_list *head)
{
head = malloc(sizeof(struct c_list));
//head->next = head;
head->id = 10;
}
int main(int argc, char **argv)
{
struct c_list *head;
init(head);
printf("id value: %d\n", head->id );
return 0;
}