1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include <stdio.h>
#include <stdlib.h>

typedef struct _Node {
    int value;            // 4 bytes
    struct _Node* next;   // 8 bytes
} Node;

int main(int argc, char* argv[]) {
    Node* hip = malloc(sizeof(*hip)); // 1 block,  12 bytes allocated
    Node* cow = malloc(sizeof(*cow)); // 1 block,  12 bytes allocated
                          //     TOTAL:  2 blocks  24 bytes allocated
    free(hip); // 1 block,   12 bytes
    free(cow); // 1 block,   12 bytes

    // In use at exit:  12 bytes allocated - 12 bytes freeed = 0
    //                   1 block allocated -  1 block freeed = 0
    return EXIT_SUCCESS;
}

© Copyright 2017 Alexander J. Quinn         This content is protected and may not be shared, uploaded, or distributed.