Lesson 27 / 38
typedef
Give types shorter names with typedef, such as a Point struct that needs no struct keyword.
A nickname for a type
typedef doesn't create a new type — it gives an existing one an alias, most often used to drop the repetitive struct keyword.
Before and after
Now Point alone works as a type name, no struct prefix needed.
typedef struct {
int x;
int y;
} Point;
int main(void) {
Point p = {1, 2};
printf("%d,%d\n", p.x, p.y);
return 0;
}
Output:
1,2