The following code compiles and runs perfectly:
typedef struct n {
char value;
struct n* next;
} node;
void insert_new_node(node** head, char new_value)
{
node* new_node = malloc(sizeof(node*));
new_node->value = new_value;
new_node->next = NULL;
if(*head == NULL)
{
*head = new_node;
}
else
{
node* current = *head;
while(current->next != NULL)
{
current = current->next;
}
current->next = new_node;
}
}
My question is - notice that I only actually malloc space for a pointer to a struct... Not for the struct itself (ref: node* new_node = malloc(sizeof(node*));
). So my question is, where is this struct data actually stored and if it is stored on the heap, how does this work?