boot2

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

084-struct-assign.c (336B)


      1 /* Struct copy via assignment operator. C99 6.5.16. */
      2 
      3 struct Pair { int a; int b; };
      4 
      5 int main(int argc, char **argv) {
      6     struct Pair x = { 3, 7 };
      7     struct Pair y;
      8     y = x;
      9     if (y.a != 3) return 1;
     10     if (y.b != 7) return 2;
     11     /* Mutating x must not affect y. */
     12     x.a = 99;
     13     if (y.a != 3) return 3;
     14     return 0;
     15 }