I'm learning C and saw this segment of code for creating a linked list :
typedef struct node {
int val;
struct node * next;
} node_t;
void print_list(node_t * head) {
node_t * current = head;
while (current != NULL) {
printf("%d\n", current->val);
current = current->next;
}
}
My question is , if current
is simply a pointer holding a memory address how can the ->
operator be applied to it in current->val
, expecting a decimal to be printed - printf("%d\n", current->val);
ignoring the format specifier surely this , would print a memory address rather than a literal value , as it hans't been dereferenced , or is it the arrow operator that does the dereferencing?