×

C Tutorial

C Basics

C Data Types

C Input/Output

C Operators

C Conditional Statements

C Control Statements

C Strings

C Functions

C Arrays

C Structure and Unions

C Pointers

C Preprocessor Directives

C Command-line Arguments

C File Handlings

C Graphics

C Advance Topics

C Tips and Tricks

C Important Topics

C Practice

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




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.