C Constants and Define Preprocessor

RSS
FACEBOOK
FACEBOOK
PINTEREST
PINTEREST
LINKEDIN
INSTAGRAM

[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.

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

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]

RSS
FACEBOOK
FACEBOOK
PINTEREST
PINTEREST
LINKEDIN
INSTAGRAM
LEARN MORE  Python Class Tutorial with Examples

Leave a Reply

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

Enjoy this blog? Please spread the word :)