boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

092-array-of-struct.c (461B)


      1 /* Local array of structs with brace-nested initializer. */
      2 
      3 struct Point { int x; int y; };
      4 
      5 int main(int argc, char **argv) {
      6     struct Point a[3] = { {1, 2}, {3, 4}, {5, 6} };
      7     int sum = 0;
      8     int i;
      9     for (i = 0; i < 3; i = i + 1) sum = sum + a[i].x + a[i].y;
     10     if (sum != 21) return 1;
     11     /* Address arithmetic on array of structs. */
     12     struct Point *p = a;
     13     if ((p + 2)->x != 5) return 2;
     14     if ((p + 2)->y != 6) return 3;
     15     return 0;
     16 }