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 | #include <stdio.h>
#include <stdlib.h>
struct PlaceFlat { // ON OUR PLATFORM
int x; // 4 bytes
char floor; // 1 byte // e.g., 'G', 'B', '1', '2'
int y; // 4 bytes
char* title; // 8 bytes
}; // TOTAL: 17 bytes == sizeof(struct PlaceFlat)
// REMINDER: use sizeof(expr) not sizeof(type)
// Compilers will typically add padding betweeen fields so that address
// of any given field is a multiple of some power of 2 (e.g., 16).
int main(int argc, char* argv[]) {
struct PlaceFlat phys112 = {.x = 1, .y = 12, .floor = 'A',
.title = "Physics 112"};
// Whatever struct fields you don't name in the named initializer
// will be initialized to zero.
//
// Likewise, with an array:
//
// int array[10] = { [2]=500, [5]=800 };
// int array[10] = { 0, 0, 500, 0, 0, 800, 0, 0, 0, 0 };
//
// As long as you have the curly braces as an initializer, any
// fields not explicitly named will be initialized to zero.
return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
|
© Copyright 2019 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.