C typedef

Intermediate
6 min read
Updated: Nov 2026
1 example

What Is typedef?

typedef gives an existing type a new alias. It is widely used to remove the struct keyword, to name function pointer types, and to hide platform-specific integer sizes. A typedef does not create a new type; it is another name for the old one.

Remember
typedef unsigned char byte;
typedef struct { int x, y; } Point;
typedef int (*BinOp)(int, int);

Point p = {3, 4};
BinOp op = add;

Cheat Sheet

Keep these facts handy while you work with typedef in C.

TopicDetail
Aliastypedef old new;
Structtypedef struct {...} Name;
Function pointertypedef ret (*Name)(args);
ConventionCapitalized or _t suffix

C Examples

Compile each example with gcc file.c -std=c11 -Wall -o out. Next: Bit-fields.

Example 1 — Aliases for a struct and a function pointer

The code reads more cleanly without repeated struct and pointer syntax.

C
#include <stdio.h>

typedef struct { int x, y; } Point;
typedef int (*BinOp)(int, int);

static int add(int a, int b) { return a + b; }

int main(void) {
    Point p = {3, 4};
    BinOp op = add;

    printf("Point (%d,%d)\n", p.x, p.y);
    printf("result=%d\n", op(p.x, p.y));
    return 0;
}

How It Works

  1. Point replaces struct Point everywhere.
  2. BinOp names the pointer-to-function type once.
  3. op(3, 4) calls add through the alias.

Edge Cases & Pitfalls

Check these before relying on typedef in real programs.

hide

Hiding pointers

typedef struct Node *NodePtr; makes code harder to read. Keep the * visible.

posix

Reserved _t suffix

POSIX reserves names ending in _t. Avoid creating new ones in libraries.

Key Takeaways

  • Alias: not a new type.
  • Readability: shorten long declarations.
  • Keep pointers visible.

One line: typedef gives an existing type a new alias.

Frequently Asked Questions

typedef creates an alternate name for a type, making complex declarations such as function pointers or structs easier to read and port.
No. typedef is handled by the compiler and respects scope and type rules, while #define does plain text substitution.
Continue with "C Bit-fields" next. Pack small values into a specific number of bits inside a struct. The C Structures, Unions and Enums hub lists every topic in order.

Next: Bit-fields

Pack small values into a specific number of bits inside a struct.

Continue →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful