Difference between the typedef and the #define in C
Categories: C language
Following are the differences of the typedef and the #define, as follows:
SN - Typedef - #define
1.Typedef is a keyword in the C programming language.#define is a pre-processor and used as macro used in C programming.
2.It is a keyword used to provide an alternate name to the existing data types only. And that name can be used to initialize the variables in a program.A #define is used to define an alias for values.
3.The compiler performs it.The pre-processor performs it.
4.It uses a semicolon to terminate the statement.It does not use a semicolon to terminate the statement.
5.It defines the actual definition of a new data type.A #define is used to just copy-paste the define values where it calls or uses.
6.It follows the scope rule that defines if a new data type is in scope (inside a function), the new type name will only be visible till the scope of the data type.When the #define pre-processor encounters in a program, it replaces all the occurrence of the variables with the defined values; after that, no scope is followed.
7.Define outside of the main() function.Define outside of the main() function.