1.14. The Keyword const

[ fromfile: const-intro.xml id: const-intro ]

[Note]Note

In some C/C++ programs, you might see constants defined as preprocessor macros like this:

#define STRSIZE 80
[...]
char str[STRSIZE];

Preprocessor macros get replaced before the compiler sees them. Using macros instead of constants means that the compiler cannot perform the same level of type checking as it can with proper const expressions. Generally const expressions are preferred to macros for defining constant values in C++ programs. Other uses of the preprocessor can be found in Section C.2.