To make the variable a
read-only, we apply the
const qualifier
to its declaration. Once initialized or assigned to, these variables become read-only. Attempting to change their values results in a
compile-time error. Let us write an example that defines a few simple constants:
int main(void)
{
const char c = 'a';
const int x = 123;
const double d = 456.789;
printf("We have defined three constants.\n");
printf("Their values are: %c, %d, %.3f.\n", c, x, d);
}
Output:We have defined three constants.
Their values are: a, 123, 456.789.
This ...