Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

typedef vs #define

**Difference**

1) typedef is limited to giving symbolic names to types only, whereas #define can be used to define an alias for values as well, e.g., you can define 1 as ONE, 3.14 as PI, etc.
2) typedef interpretation is performed by the compiler where #define statements are performed by preprocessor.
3) #define should not be terminated with a semicolon, but typedef should be terminated with semicolon.
4) #define will just copy-paste the definition values at the point of use, while typedef is the actual definition of a new type.
5) typedef follows the scope rule which means if a new type is defined in a scope (inside a function), then the new type name will only be visible till the scope is there. In case of #define, when preprocessor encounters #define, it replaces all the occurrences, after that (No scope rule is followed).
 
PREVIOUS NEXT
Tagged: #typedef
ADD COMMENT
Topic
Name
3+6 =