typedef is for defining something as a type. For instance:

typedef struct {
  int a;
  int b;
} THINGY;

...defines THINGY as the given struct. That way, you can use it like this:

THINGY t;

...rather than:

struct _THINGY_STRUCT {
  int a;
  int b;
};

struct _THINGY_STRUCT t;

...which is a bit more verbose. typedefs can make some things dramatically clearer, specially pointers to functions.

Answer from T.J. Crowder on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ c_typedef.php
C typedef
C Examples C Real-Life Examples C Exercises C Quiz C Code Challenges C Practice Problems C Compiler C Syllabus C Study Plan C Interview Q&A C Certificate ... The typedef keyword lets you create a new name (an alias) for an existing type.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ typedef-in-c
C typedef - GeeksforGeeks
July 23, 2025 - The C typedef keyword is used to redefine the name of already existing data types. When names of datatypes become difficult to use in programs, typedef is used with user-defined datatypes, which behave similarly to defining an alias for commands.
Discussions

new to C. what does typedef mean in this case and why's it used?
There are two completely different ways to name a struct type. You can use: struct statement { /* ... */ }; in which case the name of the type is struct statement. Or you can use: typedef struct { /* ... */ } Statement; in which case the name of the type is Statement. Technically speaking, what the latter statement is doing is defining an anonymous (or tagless) struct type, then binding that type to a name. Some people think the former approach is better since: it keeps the identifier statement out of the regular identifier namespace (struct tags have their own namespace); you can forward-declare the type (you can't forward-declare a typedef since it's a definition, not a declaration); and it is clear when using the type that it is describing a structure and not a primitive type (which can be important sometimes since it affects how it works in function parameters and return values). Some people think the latter approach is better since: you don't have to type struct so often; and you can change whether something is struct or not without necessarily changing any of the code that uses the type. All of what I've described here applies to enum types, union types, or, for that matter, any other type. You could use: typedef int *IntPointer; to define an IntPointer type, for instance, if you would prefer to write that instead of int *. More on reddit.com
๐ŸŒ r/cprogramming
4
2
April 6, 2022
Is it bad to use typedef?
Programming languages allow you to use the principle of abstraction to define solutions to problems. Typedefs in C are nothing more than syntactic sugar which allows you to define a type synonym for a complex object. You use these type synonyms to make your code more readable and more understandable. It's the same reason you define functions. You want to replace a complex sequence of symbols with a simpler, more meaningful symbol. The true test for whether or not your code is easy to read and maintain is if an equally skilled individual can understand the code you've written. The same applies to you, the author, if you cannot understand the code you've written 6 to 12 months after you last touched it, that's proof that your code was not clearly written. More on reddit.com
๐ŸŒ r/C_Programming
58
61
June 27, 2020
How to properly use `typedef` for structs in C? - Stack Overflow
I see a lot of different typedef usages in many C courses and examples. Here is the CORRECT way to do this (example from ISO/IEC C language specification draft) typedef struct tnode TNODE; struct ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
When is it appropriate to typedef?
Very good questions. I've been programming in C for eons and had never really thought about it. I think the decision is primary a personal preference, but for what it's worth, I've never seen your Option 1 used anywhere -- always Option 2. If I was looking at someone else's code, I'd be looking for a typedef, not a #define. The latter would be very strange. What I like about using a typedef for a struct or union declaration is: I can use a CamelCase name for the "object" and also the struct keyword by itself (as in your Option 2). The type name is one word instead of two, easier to type, and more readable. The name also connotes that the type is complex and can be considered an "object", which is how I like to think of it. So I instinctively know to pass it around by reference instead of by value and am always cognizant of where the object itself is (on the stack, on the heap, ??) so I don't forget to free() it if necessary when I'm done using it. Like you, I don't like to have to code superfluous struct and union keywords everywhere. StrList is definitely preferable to struct StrList. I also agree that you should not add _t. That way, you can easily distinguish standard type names from your own. More on reddit.com
๐ŸŒ r/C_Programming
20
11
December 26, 2015
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ cprogramming โ€บ c_typedef.htm
Typedef in C
The C programming language provides a keyword called typedef to set an alternate name to an existing data type. The typedef keyword in C is very useful in assigning a convenient alias to a built-in data type as well as any derived data type ...

typedef is for defining something as a type. For instance:

typedef struct {
  int a;
  int b;
} THINGY;

...defines THINGY as the given struct. That way, you can use it like this:

THINGY t;

...rather than:

struct _THINGY_STRUCT {
  int a;
  int b;
};

struct _THINGY_STRUCT t;

...which is a bit more verbose. typedefs can make some things dramatically clearer, specially pointers to functions.

Answer from T.J. Crowder on Stack Overflow
๐ŸŒ
Reddit
reddit.com โ€บ r/cprogramming โ€บ new to c. what does typedef mean in this case and why's it used?
r/cprogramming on Reddit: new to C. what does typedef mean in this case and why's it used?
April 6, 2022 -
typedef enum { STATEMENT_INSERT, STATEMENT_SELECT } StatementType;

typedef struct {
  StatementType type;
} Statement;

example, in this case, what is the benefit? I know what enums are, but what does the struct do also?

Top answer
1 of 2
11
There are two completely different ways to name a struct type. You can use: struct statement { /* ... */ }; in which case the name of the type is struct statement. Or you can use: typedef struct { /* ... */ } Statement; in which case the name of the type is Statement. Technically speaking, what the latter statement is doing is defining an anonymous (or tagless) struct type, then binding that type to a name. Some people think the former approach is better since: it keeps the identifier statement out of the regular identifier namespace (struct tags have their own namespace); you can forward-declare the type (you can't forward-declare a typedef since it's a definition, not a declaration); and it is clear when using the type that it is describing a structure and not a primitive type (which can be important sometimes since it affects how it works in function parameters and return values). Some people think the latter approach is better since: you don't have to type struct so often; and you can change whether something is struct or not without necessarily changing any of the code that uses the type. All of what I've described here applies to enum types, union types, or, for that matter, any other type. You could use: typedef int *IntPointer; to define an IntPointer type, for instance, if you would prefer to write that instead of int *.
2 of 2
2
Typedef in these cases names a new type for your code. In these cases, you can use Statement and StatementType to refer to structs that look like the former, and the latter enum. Whenever you are in this scope.
Find elsewhere
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ Typedef
typedef - Wikipedia
2 weeks ago - typedef is a reserved keyword in the programming languages C, C++, and Objective-C. It is used to create an additional name (alias) for another data type, but does not create a new type, except in the obscure case of a qualified typedef of an array type where the typedef qualifiers are transferred ...
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ cpp โ€บ c-language โ€บ typedef-declarations
Typedef Declarations | Microsoft Learn
August 11, 2025 - A typedef declaration doesn't create new types. It creates synonyms for existing types, or names for types that could be specified in other ways. When a typedef name is used as a type specifier, it can be combined with certain type specifiers, ...
๐ŸŒ
Reddit
reddit.com โ€บ r/c_programming โ€บ is it bad to use typedef?
r/C_Programming on Reddit: Is it bad to use typedef?
June 27, 2020 -

When making various structs, unions, enums, etc. is it bad to use typedef? I was looking at someone elseโ€™s code and for a struct they would always just specify that it was a struct whenever they referenced it in code instead of using typedef. I was wondering if there was a stylistic guideline or a set of rules on using typedef.

๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ keywords โ€บ typedef
C | Keywords | typedef | Codecademy
January 27, 2025 - The typedef keyword in C is used to create a new name (alias) for an existing data type, primarily to simplify complex data types. This improves code readability and maintainability.
๐ŸŒ
Unstop
unstop.com โ€บ home โ€บ blog โ€บ typedef in c | usage with mulitple data types (+examples)
Typedef In C | Usage With Mulitple Data Types (+Examples)
May 15, 2024 - Typedef in C is a reserved keyword used to create an alias/ new name for existing data types. The primary purpose is to simplify complex type declarations in code.
Top answer
1 of 2
15

What this does:

typedef struct {
    int a;
    int b;
} ab_t;

Is define an anonymous struct and give it the alias ab_t. For this case there's no problem as you can always use the alias. It would however be a problem if one of the members was a pointer to this type.

If for example you tried to do something like this:

typedef struct {
    int count;
    TNODE *left, *right;
} TNODE;

This wouldn't work because the type TNODE is not yet defined at the point it is used, and you can't use the tag of the struct (i.e. the name that comes after the struct keyword) because it doesn't have one.

2 of 2
7

The difference between these two typedef declarations

typedef struct tnode TNODE;

struct tnode {
    int count;
    TNODE *left, *right;
};

TNODE s, *sp;

and

typedef struct {
    int a;
    int b;
} ab_t;

. is that in the second case you declared an unnamed structure. It means that within the structure you can not refer to itself. For example you can not write

typede struct {
    int count;
    TNODE *left, *right;
} TNODE;

because the name TNODE used in this member declaration

    TNODE *left, *right;

is not declared yet.

But you can refer to the structure if the structure tag will have a name like

struct tnode {
    int count;
    struct tnode *left, *right;
};

because the name struct tnode was already declared.

Another difference is that to declare a pointer to a structure there is no need to have a complete definition of the structure. That is you may write

typedef struct tnode TNODE;

TNODE *sp;

struct tnode {
    int count;
    TNODE *left, *right;
};

Pay attention to that you may write a typedef declaration also the following way

struct tnode {
    int count;
    struct tnode *left, *right;
} typedef TNODE;
๐ŸŒ
cppreference.com
en.cppreference.com โ€บ cpp โ€บ language โ€บ typedef
typedef specifier - cppreference.com
May 11, 2025 - Every identifier introduced in this declaration becomes a typedef name, which is a synonym for the type of the object or function that it would become if the keyword typedef were removed. The typedef names are aliases for existing types, and are not declarations of new types. typedef cannot be used to change the meaning of an existing type name (including a typedef name).
๐ŸŒ
Reddit
reddit.com โ€บ r/c_programming โ€บ when is it appropriate to typedef?
r/C_Programming on Reddit: When is it appropriate to typedef?
December 26, 2015 -

This is probably a stupid question, or it hinges on preference, or it's so obvious/often-asked that I should be ashamed. I'll accept whatever rebuke you deem appropriate, because I couldn't search up an answer.

When should I use a typedef?

One of the first questions I asked on here involved the use of a typedef on a struct where I used the _t suffix. One of the mods politely pointed out that I shouldn't be using said suffix because it is reserved for POSIX types, and (in my opinion more importantly) there is nothing wrong with just typing struct each time I reference my structure. But, of course, I'm too lazy for that, and so I've been using the preprocessor to #define a shortened struct call. Is this appropriate? Is there any advantage to using a typedef? Are there case specific instances of it being advantageous? Or would I just be risking namespace pollution? Do I risk making my code less readable by avoiding the typedef keyword?

TL;DR: Which of these would you condone/condemn? If either please elaborate.

/* Option 1 */
#define sVec struct oVec
/* Note: sVec is used later to avoid typing struct repeatedly */
struct oVec {       /* I don't use sVec here for code clarity */
    int x, y, z;
};

/* Option 2 */
typedef struct {
    int x, y, z;
} tVec;

/* Generalized functions; @Vec could be sVec or tVec 
   but either should be used consistently throughout*/
@Vec * Vec_new()
{
    @Vec *self = malloc(sizeof(@Vec));
    self->x = 0;
    self->y = 0;
    self->z = 0;
    return self;
}
void Vec_dst(@Vec *self)
{
    free(self);
    return;
}
/* Insert other useful functions like Vec_Get_x, Vec_Set_x,
   and similar for y and z */

EDIT: formatting, spellchecking, minor clarifications, typo fixing, style decisions...

Top answer
1 of 5
10
Very good questions. I've been programming in C for eons and had never really thought about it. I think the decision is primary a personal preference, but for what it's worth, I've never seen your Option 1 used anywhere -- always Option 2. If I was looking at someone else's code, I'd be looking for a typedef, not a #define. The latter would be very strange. What I like about using a typedef for a struct or union declaration is: I can use a CamelCase name for the "object" and also the struct keyword by itself (as in your Option 2). The type name is one word instead of two, easier to type, and more readable. The name also connotes that the type is complex and can be considered an "object", which is how I like to think of it. So I instinctively know to pass it around by reference instead of by value and am always cognizant of where the object itself is (on the stack, on the heap, ??) so I don't forget to free() it if necessary when I'm done using it. Like you, I don't like to have to code superfluous struct and union keywords everywhere. StrList is definitely preferable to struct StrList. I also agree that you should not add _t. That way, you can easily distinguish standard type names from your own.
2 of 5
9
In my totally personal opinion, I'd use typedefs only for working with function pointers. (Examples below.) I'd never typedef structs and enums, because I prefer the structure of my code to be as vanilla and generic as possible. Typedefs in my opinion are "premature complexity", if that makes sense. In my experience, keeping my code crystal clear cuts down on the urge to be "clever" at the micro level, and makes it easier to be clever at the macro level by combining simple parts to do complex things. (Complexity should be an emergent property of coupling simple parts.) However, function pointers are a valid case for typedefs. Let's say you want to make a struct containing a single member called signal_handler, which is a function pointer: struct test { void (*signal_handler)(int signum, void *widget, void *user_data); }; Or you want to make a function which takes one argument, which is a function pointer: int test(void (*signal_handler)(int signum, void *widget, void *user_data)) { That's just horrible and confusing. If you create a typedef: typedef void (*SignalHandler)(int signum, void *widget, void *user_data); you can write the much more readable: struct test { SignalHandler signal_handler; }; int test(SignalHandler signal_handler) {
๐ŸŒ
Quora
quora.com โ€บ Learning-programming-Why-should-we-typedef-a-struct-so-often-in-C
Learning programming: Why should we typedef a struct so often in C? - Quora
Alot of people who are not good with C and developers that argue in favor of C++ will tell you about Cโ€™s global namespace but C also has a separate namespace for struct, union, and enum types called the tag namespace. Typedefing a struct, union, and/or enum type will have the typedef name placed in the global namespace.
๐ŸŒ
Medium
medium.com โ€บ @aserdargun โ€บ introduction-to-c-type-definitions-typedef-d5da6f7d8816
Introduction to C โ€” Type definitions: typedef
October 30, 2023 - In this case, variables, arguments, and return types declared to be OS_SEM , OS_MUT , and OS_ID will be, respectively, an array of two 32-bit unsigned integers, an array of three 32-bit unsigned integers, and a pointer to a 32-bit unsigned integer. Whenever you see a variable, argument, or return value declared to be a type that has been defined through typedef , you need only substitute the variable for the typedef symbol in the typedef definition.
๐ŸŒ
YouTube
youtube.com โ€บ watch
C typedef ๐Ÿ“› - YouTube
C typedef keyword tutorial example explained#C #typedef #keyword//typedef char user[25];typedef struct{ char name[25]; char password[12]; int id;} User...
Published ย  October 6, 2021
๐ŸŒ
cppreference.com
en.cppreference.com โ€บ c โ€บ language โ€บ typedef
Typedef declaration - cppreference.com
The typedef declaration provides a way to declare an identifier as a type alias, to be used to replace a possibly complex type name ยท The keyword typedef is used in a declaration, in the grammatical position of a storage-class specifier, except that it does not affect storage or linkage:
๐ŸŒ
TechVidvan
techvidvan.com โ€บ tutorials โ€บ c-typedef-with-examples
C Typedef with Examples - TechVidvan
August 11, 2021 - Learn about C typedef with examples. It is a predefined keyword that helps in creating user-defined name for an existing data type.
๐ŸŒ
Quora
quora.com โ€บ What-is-this-typedef-declaration-C-typedef-development
What is this โ€œtypedefโ€ declaration (C, typedef, development)? - Quora
Answer (1 of 6): Typedef is one of the key mechanisms that C provides for keeping things simple, by hiding unnecessary complexity. So, instead of declaring a variable ppl like: struct person ppl[100]; You can define some preliminary types: #define ...
๐ŸŒ
Educative
educative.io โ€บ blog โ€บ how-to-use-the-typedef-struct-in-c
How to use the typedef struct in C
May 19, 2025 - Instead of repeatedly writing out ... UserProfile or Profile. C offers the typedef keyword to allow users to specify alternative simple and desired names for the primitive (e.g....