1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | // 1. Declare a struct type
struct ▒▒▒▒ {
«field definitions» // These look identical to an assignment with no
}; // initialization (e.g., int value).
int main() {
// 2. Declare and initialize a struct object on the stack.
struct ▒▒▒▒ «name» = { .«field» = «value» };
// 3. Access a field of a struct object.
int value = «name».«field»; // read
«name».«field» = 6; // write
// 4. Access a field of a struct object using the address of the object.
int value = «addr» -> «field»; // read
«addr» -> «field» = 6; // write
// Key point: «addr» -> «field» is equivalent to (*«addr»).«field»
return EXIT_SUCCESS;
}
// This is not a real program. It is just a list of syntax covered today.
|
© Copyright 2020 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.