Home »
C programming language
For a user-defined data type, what should be used typedef or #define?
C language frequently asked question on string declaration: For a user-defined data type, what should be used typedef or #define?
Submitted by IncludeHelp, on December 20, 2017
For a user-defined data type, what should be used typedef or #define?
Both typedef and #define can be used for a user-defined data type. But, typedef is preferred because it can correctly encode pointer type.
Consider the given declarations:
typedef char * tPC
#define dPC char *
tPC ob1,obj2;
dPC ob3,ob4;
Here, ob1, ob2 and ob3 will be declared as char*, but ob4 will be declared as char (while, we want to declare ob4 as char*)