The const keyword
Most C compilers, including Open Watcom allow the const keyword (and it's part of C++). However it is part of the C syntax, not preprocessed, so it applies to a variable rather than a value at compile time that the compiler understands.Here's an example.
#include <stdio.h>The line assigning b may appear odd as it mixes #define and const. When compiled, the value 12 is substituted for c, so this line sets b to 5 + 12, i.e. 17.
int main() {
#define c 12
const int a=11;
const int b=5+c;
printf("Value of %i\n\r",a) ;
printf("Value of %i\n\r",b) ;
return 0;
}
Important Points About Const
- Once a variable is declared const it cannot be changed. The compiler will reject code that tries.
- As it can't be changed later, you must initialise it when declaring it.
const int a;
Include Files
We've already used an include file in previous examples.#include <stdio.h>The preprocessor picks up the #include and merges the header file into the source prior to compiling it.
This is how to split large C and C++ split large applications into many smaller source code files.
There are two versions of #include.
- #include <system file>
- #include "filename"
On the next page : Learn about built in preprocessor names.

