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

typedef struct {
    int x;
    int y;
} Point;

int main(int argc, char* argv[]) {
    Point p_stack = { .x = 5, .y = 7 };
    printf("p_stack.x == %d  p_stack.y == %d\n", p_stack.x, p_stack.y);  // «object».«field»

    Point* a_p_stack = &p_stack;
    printf("(*a_p_stack).x == %d  (*a_p_stack).y == %d\n", (*a_p_stack).x, (*a_p_stack).y);
    printf("a_p_stack->x == %d  a_p_stack->y == %d\n", a_p_stack->x, a_p_stack->y);

    Point* a_p_heap = malloc(sizeof(*a_p_heap));
    printf("(*a_p_heap).x == %d  (*a_p_heap).y == %d\n", (*a_p_heap).x, (*a_p_heap).y);
    printf("a_p_heap->x == %d  a_p_heap->y == %d\n", a_p_heap->x, a_p_heap->y);
    
    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.