100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
C

typedef in C

Understand C's typedef keyword to create readable type aliases for structs, pointers, and primitive types.

Basics & Data TypesBeginner7 min readJul 7, 2026
Analogies

1. Introduction

typedef is a C keyword used to create an alternative, often more readable, name (alias) for an existing data type. It does not create a genuinely new type — it simply gives the compiler another name to refer to a type that already exists.

🏏

Cricket analogy: typedef is like giving a nickname, "The Wall," to Rahul Dravid — it's just another way to refer to the same player, not a different one; the compiler still sees the exact same underlying type regardless of which name is used.

typedef is especially useful for simplifying complex declarations such as function pointers and struct types, and for improving portability by abstracting platform-specific types behind a single alias.

🏏

Cricket analogy: typedef simplifies a complicated declaration, like calling a specific fielding-position combination "the slip cordon" instead of listing every player each time; it also gives portability, letting a "wicketkeeper" role mean the right specialist whether playing Test or T20 rules.

2. Syntax

c
typedef existingType aliasName;

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

3. Explanation

The general form is 'typedef existing_type new_name;', where 'existing_type' can be any valid C type — a primitive type, a pointer type, an array type, a struct/union/enum, or even a function pointer type. After the typedef, 'new_name' can be used anywhere 'existing_type' could be used, purely as a convenience alias.

🏏

Cricket analogy: The general form "typedef existing_type new_name" works like assigning any role — batter, bowler, all-rounder, or even a specific fielding formation — a shorter squad-sheet label; whatever the original role was, the new label works everywhere the old one did.

It is critical to understand: typedef does NOT create a new, distinct type in the way a class does in object-oriented languages. It creates a synonym at compile time; the underlying representation and behavior remain identical to the original type. For example, 'typedef unsigned int uint;' makes 'uint' completely interchangeable with 'unsigned int' — the compiler treats them as the exact same type for all purposes including type checking, so a uint value can be freely assigned to an unsigned int variable and vice versa with no cast needed.

🏏

Cricket analogy: Calling someone "the Little Master" instead of "Sachin Tendulkar" doesn't create a second player — it's the exact same person, unlike drafting a genuinely new recruit; similarly, typedef's "uint" is fully interchangeable with "unsigned int," no conversion needed, unlike a truly distinct role.

A very common idiom combines typedef with struct declarations to avoid repeatedly typing 'struct' before the type name: 'typedef struct { ... } TypeName;' lets you write 'TypeName var;' instead of 'struct TypeName var;'.

🏏

Cricket analogy: Instead of announcing "the specialist wicketkeeper-batter player" every single time, a team just says "the keeper" — a shorthand everyone understands; similarly, "typedef struct {...} TypeName" lets you write just "TypeName var" instead of "struct TypeName var" every time.

Clarification: typedef is purely a naming convenience for the compiler — it does NOT create a new type, does not provide type safety beyond what the original type already has, and does not consume any additional memory.

4. Example

c
#include <stdio.h>

typedef unsigned int uint;

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

typedef Point *PointPtr;

int main(void) {
    uint age = 25;
    Point p1 = {10, 20};
    PointPtr ptr = &p1;

    printf("age = %u\n", age);
    printf("p1 = (%d, %d)\n", p1.x, p1.y);
    printf("via pointer = (%d, %d)\n", ptr->x, ptr->y);

    return 0;
}

5. Output

text
age = 25
p1 = (10, 20)
via pointer = (10, 20)

6. Key Takeaways

  • typedef creates an alias (alternate name) for an existing type — it does NOT create a new type.
  • Aliased and original types are fully interchangeable with no casting required.
  • typedef is commonly used with struct/union/enum to avoid repeating the 'struct' keyword.
  • typedef can simplify complex declarations, such as function pointers and multi-level pointers.
  • typedef improves code readability and portability but adds zero runtime overhead.

Practice what you learned

Was this page helpful?

Topics covered

#CProgrammingStudyNotes#Programming#TypedefInC#Typedef#Syntax#Explanation#Example#StudyNotes#SkillVeris#ExamPrep