// Demonstrates a structure type, // a composite structure type, and // an array of structures // Demonstrates reference vs value semantics // Compile: gcc strucarray.c // Execute: a.out #include int main(){ struct Pair {int x; int y;}; // Declare type Pair (semi after }!) struct Pair pair1, pair2, pair3; // Declare three Pairs // Demonstrate access the fields of the struct pair1.x = 1; pair1.y = 2; pair2.x = 3; pair2.y = 4; // Output the pairs, line, and array printf("pair1 = (%d, %d)\n", pair1.x, pair1.y); // pair1 = (1, 2) printf("pair2 = (%d, %d)\n", pair2.x, pair2.y); // pair2 = (3, 4) // ////////////////////////////////////////////////////// const int size = 3; // int const size = 3 also works struct Pair a[size]; // Array of Pairs // Read in values for part of the array int i, n; for (i = 0; i < size; i++){ scanf("%d", &n); // get(n); a[i].x = n; scanf("%d", &a[i].y); // get(a[i].y); } for (i=0; i