No memory was allocated. 'a' is a pointer of type struct node, but it is not a pointer to struct node. There is a huge difference....
struct node
{
int data;
};
struct node *a;
int number = 18;
a = &node; //now a has some (static) memory
a->data = number; //....and you can do this.
//.....or....
a = malloc(sizeof(struct node)); //now a has some dynamic memory
a->data = number; //....and you can do this.
------------------------------
What if you had a significant sized, complex structure?
struct node2
{
int data;
float value;
int array[12];
};
struct node2 *a;
//.... inspect the sizes of these objects:
printf("sizeof(struct node)= %d\n", sizeof(struct node));
printf("sizeof(a)= %d\n", sizeof(a));
When you look at the output of the above, ask yourself, would this next statement allocate the right amount of memory?
struct node *a = malloc(sizeof(a));