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>

typedef struct _Point {
    int x;
    int y;
} Point;
void print_point(Point p) {
    printf("{.x = %d,  .y = %d}\n", p.x, p.y);
}
void initialize_point(Point* a_p, int x, int y) { // helper, TODO: add "_"
    Point temp_point = {.x = x, .y = y}; // temp_point is on the stack
    *a_p = temp_point;
}
int main(int argc, char* argv[]) {
    //int array[] = {1, 2, 3};
    
    Point* points = malloc(sizeof(*points) * 3);
    initialize_point(&points[0], 5, 6);
    initialize_point(&points[1], 15, 16);
    initialize_point(&points[2], 15, 26);

    print_point( points[0] );
    print_point( points[1] );
    print_point( points[2] );

    free(points);

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

//      { .x =  5, .y =  6 },
//      { .x = 15, .y = 16 },
//      { .x = 25, .y = 26 }
//  };

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