Lesson 26 / 36
typedef
Give a type a shorter, custom name.
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