Posts tagged How to use typedef statement
The C preprocessor blindly expands the macro with whatever they are defined with. Let us examine the following example.
#define CHARPTR char* CHARPTR p1,p2;
The C preprocessor expands the above code to the following.
But we would like p2 to be a character pointer but not a character variable.
So macro are not generally used for variable type definitions as they are not suitable for all sorts of usages. Instead typedef is used as shown below.
typedef char* CHARPTR; CHARPTR p1,p2;
With the above code, the variables p1 and p2 will effectively become character pointers.