// Using
a properly initialized constant variable.
#include
<iostream>
int main()
{
const int x = 7; // initialized constant variable
cout << "The
value of constant variable x is: "
<< x << endl;
return 0;
// indicates successful termination
} // end main
// Mistakes using const
int main()
{
const int x; // Error: x must be
initialized
x = 7; // Error: cannot modify a const variable
return 0; // indicates successful
termination
} // end main
Uninitialized const results in a syntax error.
Attempting to modify the const is another error.
Can only assign a value when the const variable is declared.