1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
// Declare a "struct type" called "struct Node".
struct Node { // for a linked list of integers
int value;
struct Node* next;
}; // DON'T FORGET THE SEMICOLON AT THE END OF A STRUCT TYPE DEFINITION
int main(int argc, char* argv[]) {
// Create a linked list with one int on the STACK.
//
// Note: Nearly all linked lists are on the heap. This is just an
// introduction to the topic.
// Create one node with value 5
struct Node head_node = { .value = 5, .next = NULL };
// Declare a variable called «head_node».
// Type of «head_node» is «struct Node».
printf("head_node.value == %d\n", head_node.value);
printf("head_node.next == %p\n", (void*)head_node.next);
return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
|
© Copyright 2020 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.