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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.