abcd12344445555
Programmer
In the following code why does the pointer [highlight]head[/highlight] is still null after function calling? Thanks.
Code:
#include <stdio.h>
#include <stdlib.h>
struct list_element{
int info;
struct list_element * next;
};
typedef struct list_element item;
void alloc(item *head){
printf("%p\n", head);
head = (item * ) (malloc(sizeof(item)));
if(head){
printf("malloc ok! : %p\n",head);
}
}
int main(int argc, char *argv[])
{
item [highlight]*head[/highlight];
[highlight]head[/highlight] = NULL;
alloc([highlight]head[/highlight]);
//Why after this point head is still NULL?
if([highlight]head[/highlight] == NULL){
printf("null\n");
}
else{
printf("Not null!\n");
}
printf("ptr main : %p\n", [highlight]head[/highlight]);
system("PAUSE");
return 0;
}