Constants
Constants are data values that cannot be change during the execution of a program. Like variables, constants have a type.
We discusse three types of constants:
Literal Constants
A literal is an unnamed constant used to specify data. If we know that the data cannot be changed, then we can simply code the data value itself in a statement.For example:
int num = 10;
Defined Constants
Another way to designate a constant is to use the preprocessor command define. Like all preprocessor commands, it is prefaced with the pound sign (#).A typical define command might be
#define PI 3.1416
Define commands are usually placed at the beginning of the program, although they are legal anywhere. Placing them at the beginning of the program makes them easy to find and change.Memory Constants
The third way to use a constant is with memory constants. Memory constants use a C type qualifier to indicate that the data cannot be changed. We have seen how to define a variable, which does nothing more than give a type and size to a named object in memory. Now let us assume that we want to fix the contents of this memory location so that they cannot be changed. This is exactly the concept of a constant, only now we have stored it in memory and given it a name. The example of memory constant is:const float pi = 3.1416;