/* struct_array.c Written by Tanya Amert for Fall 2024. Demonstrates working with arrays of structs in C. To compile this program: gcc -Wall -Werror -Og -o struct_array struct_array.c To run this program: ./struct_array */ #include // A simple struct typedef struct { int n; int n2; } simple_t; // <-- treat this as a "type" name // Builds a struct and prints its values int main() { // Create an array to hold 4 structs of type simple_t simple_t arr[4]; // Fill in the values for each struct in the array for (int i = 0; i < 4; i++) { arr[i].n = i; arr[i].n2 = i * i; } // Print out the values for each struct in the array for (int i = 0; i < 4; i++) { printf("The struct at index %d contains %d and %d.\n", i, arr[i].n, arr[i].n2); } return 0; }