typedef()
The typedef
keyword is used to create a new type definition:
Syntax:
Example:
In this example, we use typedef
to create a new type my_int
which is an alias for int
. We then declare a variable x
of type my_int
and initialize it to the value 5. Finally, we print the value of x
using printf()
.
Benefits:
Using typedef
can make code more readable and maintainable by giving meaningful names to data types. It also allows for easier modification of types throughout the codebase.
Usage:
To create a new type alias for an existing type:
To create a new type alias for a pointer type:
To create a new type alias for a function pointer:
To create a new type alias for a struct:
To create a new type alias for an enum: