Search code examples
ctypedefadtabstract-data-type

I cannot understand the point of this simple code


I am doing this assignment, and there are some stuff (from start-up materials) that I cannot comprehend.

typedef enum
{
    NORTH,
    EAST,
    SOUTH,
    WEST,
    NUM_POINTS
} Point;

typedef Point Course[NUM_POINTS] ;

I don't get the idea behind the last line , and how can I use it in the code?


Solution

  • typedef a b;
    

    Makes b an alias for type a, e.g.

    typedef int foo;
    
    int bar;
    foo bar;
    

    both bars are equivalent. In your case,

    typedef Point Course[NUM_POINTS] ;
    

    Makes Course an alias for type Point[NUM_POINTS] (where NUM_POINTS == 4), so

    Course baz;
    Point baz[NUM_POINTS];
    

    are equivalent.