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

// Define a struct type called 'struct Point' (2 words) containing two int fields.
struct Point {
    int x;  // field
    int y;  // field
};
// Defining a type does not allocate any memory or create any variable.

void print_point(struct Point point) {
    printf("point.x == %d\n", point.x);
    printf("point.y == %d\n", point.y);
}

int main(int argc, char* argv[]) {
    // Create Point object
    // … and initialize with the field values .x=5 and .y=7.
    struct Point p = { .x = 5,  .y = 7 };  // This syntax is called a named initializer.
                                           // Use this wherever possible.

    // Print the Point object
    print_point(p);

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

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