C Structs


Struct & Struct Pointer Example

    #include <stdio.h>

    /* Code illustrating struct & struct ptr */


    struct point {
           int x;
           int y;
    };


    main()
    {
      struct point p;
      struct point * pp;

      p.x = 3;
      p.y = 4; 

      printf("x: %d, y: %d\n", p.x, p.y);

      pp = &p;

      printf("x: %d, y: %d\n", pp->x, pp->y);

      /* A clunkier way of writing this is:
              printf("x: %d, y: %d\n", (*pp).x, (*pp).y);
      */
    }


Alyce Brady, Kalamazoo College