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

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*)





Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.



Comments and Discussions





© https://www.includehelp.com (2015-2018), Some rights reserved.




close Like other websites, this site uses cookies to deliver relevant ads based on your interest, by using our website, you acknowledge that you have read our privacy policy.