Dereferencing a pointer to a structure
I recently encountered this question.
A singly linked list was created, the node for the list looked like
struct node
{
int data;
struct node* link;
};
The list was created using add at head, the list looks like
100->200->300
The display function was written as
void display(struct node* head)
{
while(head != NULL)
{
printf ("%d", *head);
head=head->next;
}
}
Is this a legal way of accessing the data in the list? I tied it against
the GCC compiler, it threw a warning but it worked. Would it lead to
errors for some cases?
No comments:
Post a Comment