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

struct City {
    int longitude;  // `longitude` is a field within a struct type called `struct City`.
    int latitude;   // `latitude`  "  " "     "      " "      "    "       "      "
    char* name;     // `name`      "  " "     "      " "      "    "       "      "
    char* reason;   // `reason`    "  " "     "      " "      "    "       "      "
};  // ☆☆☆☆☆☆☆☆☆☆  REMEMBER THE SEMICOLON!!!!  ☆☆☆☆☆☆☆☆☆☆

int main(int argc, char* argv[]) {
    // Declare and initialize a struct object called `hometown` of type `struct City`.
    struct City hometown = { .longitude = 71,
                             .latitude  = 42,
                             .name      = "Boston",
                             .reason    = "it has a rich history"};
    // Q: Does order of fields in initializer matter?
    // A: Order of fields in a named initializer does not matter.

    log_int(hometown.longitude);
    log_int(hometown.latitude);
    printf("My favorite city is %s (at %d°/%d°) because %s.\n",
            hometown.name,
            hometown.longitude,
            hometown.latitude,
            hometown.reason);

    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.