Memory allocation confusion in Link List

Consider a very simple Link list prog:

What my confusion in below prog is while using malloc to allocate memory if we give malloc(sizeof(struct node)), then i understand. But I guess it should not work on giving malloc(sizeof(struct node *)), but its working fine in that case too. How I dont undersand.

#include<malloc.h>

struct node
{
int info;
struct node *link;
};
int main()
{
int num;
char a;
struct node *start=NULL,*temp,*point;
clrscr();
do
{
temp=(struct node *) malloc(sizeof(struct node *));
if(start==NULL)
{
start=temp;
point=temp;
}
else
{
point->link=temp;
point=temp;
}
printf("enter info\n");
scanf("%d",&num);
point->info=num;
point->link=NULL;
printf("want to enter more nodes\n");
a=getch();
}while((a=='y')||(a=='Y'));

}
It's not working fine. It's appearing to, while waiting to bite you in your ass at a time of its choosing.
thanks cire, yaa I know that it should not work....but why I am saying that it's wrkng because its giving the right output in every case be it normal traversal(as shown in above code) or in searching algos etc. What I totally don't understand is that when the node is only getting the size of a pointer, how its properly storing the info as well as the address of next node.
Topic archived. No new replies allowed.