Concept Flow - Typedef keyword
Write typedef statement
Compiler creates new type name
Use new type name in code
Code compiles with alias type
The typedef keyword creates a new name (alias) for an existing type, making code easier to read and write.
typedef unsigned int uint; uint age = 30; printf("Age: %u\n", age);
| Step | Action | Evaluation | Result |
|---|---|---|---|
| 1 | Read typedef unsigned int uint; | Create alias 'uint' for 'unsigned int' | Alias 'uint' ready to use |
| 2 | Declare variable 'age' of type 'uint' | uint means unsigned int | Variable 'age' of type unsigned int created with value 30 |
| 3 | Print value of 'age' | age = 30 | Output: Age: 30 |
| 4 | End of program | No more statements | Program ends successfully |
| Variable | Start | After Declaration | Final |
|---|---|---|---|
| age | undefined | 30 | 30 |
typedef creates a new name for an existing type Syntax: typedef existing_type new_name; Use new_name as a type in declarations Helps make code clearer and easier to read Does not create a new type, just an alias