Type of #define variables

It has no type. It is a simple text substitution. The text 5000 will be dropped in place wherever MAXLINE appears as a token.

For example:

int a = MAXLINE;

will put the value 5000 in a.



will not result in

char *50002 = "5000";

So, if you want type-checking, macro’s are not the way to go. You will want to declare static constants instead, that way type-checking is done by the compiler.

For information on the differences between static, const, and #define, there are many sources, including this question: Static, define, and const in C

Leave a Comment