boot2

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

090-incdec-member.c (536B)


      1 /* Pre/post increment on struct members and through pointers. */
      2 
      3 struct S { int x; int y; };
      4 
      5 int main(int argc, char **argv) {
      6     struct S s = { 5, 10 };
      7     int a = s.x++;          /* a=5, s.x=6 */
      8     int b = ++s.y;          /* b=11, s.y=11 */
      9     if (a != 5 || s.x != 6) return 1;
     10     if (b != 11 || s.y != 11) return 2;
     11 
     12     struct S *p = &s;
     13     int c = p->x++;         /* c=6, s.x=7 */
     14     int d = --p->y;         /* d=10, s.y=10 */
     15     if (c != 6 || s.x != 7) return 3;
     16     if (d != 10 || s.y != 10) return 4;
     17     return 0;
     18 }