Quick Contact

✉
fahimkhan20148@gmail.com
📱
+971 507 286 133
Back to Notes
August 28, 2026
ctypestypedef

Typedef in C

A type alias is used to declare an alias for an existing type. For all computational purposes both are the same type; a type alias is largely just for syntax.

The original type is still valid; it's just another name for the type.

typedef is a keyword used to declare a type alias for an existing type. For all computational purposes both are the same type; typedef is largely just for syntax.

#include <stdio.h>

typedef int USD;

int main(void) {
    USD cur = 50;
    int num = 10;

    int total = cur + num; // Perfectly valid
    printf("Total: %d\n", total); // Outputs: Total: 60

    return 0;
}

USD is still valid; it's just another name for the type.

Typedef with Structs

typedef struct {} Point;

Point point = {};

struct Point2 {};
struct Point2 point2 = {};

With struct, the above pattern of naming an anonymous struct to Point using typedef is so we don't have to type struct Point the type and name each time we want to use point, unlike struct Point2.

Recursive Structs

typedef struct Node {
    int val;
    struct Node* left;
    struct Node* right;
} Node;

Node node = {};

We can use a typedef for a named struct when defining a recursive struct.