logo

Short introduction to linked lists in C

#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct Node { int x; struct Node* next; } Node; int main(int argc, char* argv[]) { Node root; root.x = 15; root.next = malloc(sizeof(Node)); root.next->x = -2; root.next->next = NULL; printf("First: %d\n", root.x); printf("Second: %d\n", root.next->x); return 0; }
Course thumb

The C programming language made simple