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 <iostream>The line assigning a value to 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.
using namespace std;
int main() {
#define c 12
const int a=11;
const int b=5+c;
cout << "Value of a= " << a << endl ;
cout << "Value of b= " << b << endl ;
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 initialize it when declaring it.
const int a;Const has many more uses in function parameters and return types and we'll come back to these in the future.
Include Files
We've already used an include file in previous examples.#include <iostream>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.

