I've been searching around for a good while now on google and a few text books and I can't seem to understand why it is, when building a linked list, that the nodes need to be pointers.
Eg. If i have a node defined as:
typedef struct Node{
int value;
struct Node *next;
} Node;
why is it that in order to create a linked list, I would say:
Node *a = malloc(sizeof(Node));
Node *b = malloc(sizeof(Node));
a->value = 1;
b->value = 2;
a->next = b;
b->next = NULL;
rather than:
Node a, b;
a.value = 1;
b.value = 2;
a.next = &b;
b.next = NULL;
To my understanding, the list will still be able to be referenced and traversed as normal, the only difference is the use of the dot, ampersand syntax rather than the arrow?
Node *a, *bsnippet is invalild. You're declaring pointer variables, without having them point to valid memory. The pointers almost certainly won't point to validNodeobjects