Using #define

The #define command defines a string substitution. If you write

#define BIG 512

you have instructed the precompiler to substitute the string 512 wherever it sees the string BIG. But this is not a string in the C++ sense. The characters 512 are substituted in your source code wherever the token BIG is seen. A token is a string of characters that can be used wherever a string or constant or other set of letters might be used. Therefore, if you write

#define BIG 512
int myArray[BIG];

the intermediate file produced by the precompiler will look like this:

int myArray[512];

Note that the #define statement is gone. Precompiler statements ...

Get Sams Teach Yourself C++ in 24 Hours, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.