C Constants and Define Preprocessor

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/c-constants-define-preprocessor/
PINTEREST
PINTEREST
INSTAGRAM

C Programming Tutorial Index

  1. Introduction To Programming
  2. C Setup Development Environment
  3. C Hello World and Compile First Application
  4. C Syntax and Basics
  5. C Variables
  6. C Numeric Variable Types (Integer, Long, Float)
  7. C String Variables
  8. C Constants and Define Processor
  9. C Operators
  10. C If Else and Switch Case Conditionals
  11. C While Loops
  12. C For Loops
  13. C Arrays
  14. C Functions
  15. C Structure
  16. C Union
  17. C File Operations (Open, Read, Write)
  18. C Pointers
  19. C Type Casting
  20. C Header Files and Include

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

C Programming Tutorial Index

  1. Introduction To Programming
  2. C Setup Development Environment
  3. C Hello World and Compile First Application
  4. C Syntax and Basics
  5. C Variables
  6. C Numeric Variable Types (Integer, Long, Float)
  7. C String Variables
  8. C Constants and Define Processor
  9. C Operators
  10. C If Else and Switch Case Conditionals
  11. C While Loops
  12. C For Loops
  13. C Arrays
  14. C Functions
  15. C Structure
  16. C Union
  17. C File Operations (Open, Read, Write)
  18. C Pointers
  19. C Type Casting
  20. C Header Files and Include
RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/c-constants-define-preprocessor/
PINTEREST
PINTEREST
INSTAGRAM

Leave a Reply

Your email address will not be published.