khuang8493
6/20/2018 - 11:57 PM

Define Constants in C

Defining constants in C

Define value of constants in  C:

C provides a preprocessor directive (also called a macro) for creating symbolic constants.

#define NAME value_of_this_constant

This goes at the very top of the program.

At the time your program is compiled, #define goes through your code and replaces NAME with the value defined.

Example:

#define PI 3.14159265

At the time your program is compiled, #define goes through your code and replace all the PI with the value "3.14159265".

This way to define constant so the prgram is more meaningful, and we can change the value of the constant easily without going through the whole program and change each one.

The constant name usual is capitalized. So we know it's a constant.