C Typedef


Typedef Examples

    #include <stdio.h>

    /* Code illustrating typedef */
         (typedefs are usually found in header files) */

    /* Define String as an alias for char *  */
    typedef  char *  String;
    
    /* Define Boolean as an alias for an enum  */
    typedef  enum{FALSE, TRUE}  Boolean;

    /* WAS
        struct point {
               int x;
               int y;
        };
    */

    typedef struct {
           int x;
           int y;
    } Point;


    main()
    {
      /* WAS
          struct point p;
          struct point * pp;
      */
      Point p;
      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);
    }


Alyce Brady, Kalamazoo College