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

// Q: What would the equivalent array look like?

/*
// STRUCT TYPE DEFINITION for `struct Point`
struct Point {
    int x;   // `x` is a field within the type `struct Point`
    int y;   // `y` is a field within the type `struct Point`
};  // <<<<< DO NOT FORGET THIS SEMICOLON <<<<<
*/

int main(int argc, char* argv[]) {
    // Declare and initialize a struct object of type `struct Point`
    
    //struct Point p = { .x = 5, .y = 6 };  // <<< "named initializer"
    int p[2] = { 5, 6 };

    //log_int(p.x);
    log_int(p[0]);

    //log_int(p.y);
    log_int(p[1]);

    //printf("My favorite point is at (%d, %d)\n", p.x, p.y);
    printf("My favorite point is at (%d, %d)\n", p[0], p[1]);

    // When you have a struct object (e.g., `p`), you can refer to the
    // fields within it using ▒.▒.
    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.