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
29
30
31
32
// Okay to copy/adapt for HW07 in ECE 26400 Spring 2020.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>

// Declare a "struct type" called "struct Node" for a linked list of ints.
struct Node {           // On our platform…
    int value;          //   4 bytes
    struct Node* next;  //   8 bytes
};       // entire object:  12 bytes


int main(int argc, char* argv[]) {
    // Create a linked list with one int on the HEAP.

    // Create one node with value 5

    struct Node* head = malloc(sizeof(*head));
    // (*head).value = 5;  // ugly way
    // (*head).next  = NULL;
    head -> value = 5;     // pretty way
    head -> next  = NULL;  // pretty way

    printf("head -> value == %d\n", head -> value);
    printf("head -> next  == %p\n", (void*)head -> next);

    free(head);

    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.