typedef Type alias declarations
typedef Type alias declarations
typedef aliases a type to simplify declarations. It creates no new type or safety, obeys scope and declaration syntax, and is not text substitution.
| Category | Storage-class specifiers |
|---|---|
| Kind | Keyword / Statement |
| C standard | C89 / C90 |
📝 Syntax
typedef unsigned int uint;
▶ Example
Edit the C code below and click Run; the server compiles and executes it:
Output:
count = 2, sum = 7
🏷️ Related storage-class specifiers
📚 Related Tutorials
❓ FAQ
QHow does typedef differ from #define for type names?
AThe compiler processes typedef using declaration syntax and scope rules, so it handles composite types such as pointers and arrays correctly. #define performs preprocessor text substitution without type semantics, which can produce different results in complex declarations.
QDoes typedef create a completely new type?
ANo. A typedef name is only an alias for the original type, with the same compatibility and conversion rules. typedef alone therefore cannot provide strong-type isolation for units or similar domains.
QHow are the names after typedef struct used?
AIn typedef struct Point { int x; } Point;, the first struct Point is the tag and the final Point is the type alias; either form can declare objects. An anonymous structure has no tag, so it relies on names introduced by declarations such as the alias.