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
33
34
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include "clog.h"

// Q: What if we had used an array instead of a struct?
// A: Arrays treat the fields as having the same role.  Struct types let you express
//    your code the way you think about it.  “Say what you mean and mean what you say.”

/*
// STRUCT TYPE DEFINITION for type `struct Point` using the cannonical struct syntax.
struct Point {
    int x;   // `x` is a field within a struct type called `struct Point`.
    int y;   // `y` "  " "     "      " "      "    "       "      "
};  // ☆☆☆☆☆☆☆☆☆☆  REMEMBER THE SEMICOLON!!!!  ☆☆☆☆☆☆☆☆☆☆
*/

int main(int argc, char* argv[]) {
//  struct Point p = { .x = 5, .y = 6 };
    int p[2] = { 5, 6 };

//  log_int(p.x);  // `p.x` refers to the `.x` field of struct object `p`.
    log_int(p[0]);

//  log_int(p.y);  // `p.y` refers to the `.y` field of struct object `p`.
    log_int(p[1]);

//  printf("The coordinates of `p` are (%d, %d)\n", p.x, p.y);
    printf("The coordinates of `p` are (%d, %d)\n", p[0], p[1]);

    return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */

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