C Constants and Define Preprocessor
Up to now we have worked with variables. As its names states variables values may change in the flow of application. Variables changes by adding, removing, subtracting etc. This may be ideal solution for most of time but how can we avoid it if we need constant values. Because if we want to define Pi number and do not want to change it as Pi is fixed number in mathematics. Here the solution is making them explicitly constant.
To make variables constant
const variable is used. By adding
const keyword before variable type the variable becomes a constant and can not be changed.
const float PI=3.14;
Not just numbers also other variable types can be made constant
poftut.com is string constant and can not be change during execution of the application.
const char site="poftut.com"
Define preprocessor provides another way to define constant. This way definition do not need a variable type.
#define simple puts value all occurrences of identifier
#define IDENTIFIER VALUE
Here is an example usage of
#define PI 3.14