C Constants and Define Preprocessor – POFTUT

C Constants and Define Preprocessor

[rps-include post=6557]

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.

Not just numbers also other variable types can be made constant

String Constant

Here string poftut.com is string constant and can not be change during execution of the application.


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

Here is an example usage of #define

[rps-include post=6557]

echo '

LEARN MORE  Javascript Regular Expression Operation

Leave a Reply

Your email address will not be published. Required fields are marked *