Answer: a constant in C is a fixed value that cannot be changed while the program runs.
Types of constants (literals):
- Integer constants:
10,-25,0x1F(hexadecimal),017(octal) - Real (floating-point) constants:
3.14,2.5e3 - Character constants:
'A','5','\n'(single quotes) - String constants:
"Hello"(double quotes, ends with'\0')
Two ways to define a named constant:
#define PI 3.14159 /* symbolic constant (preprocessor) */
const int MAX = 100; /* const keyword */
If you try to change it later, e.g. MAX = 200;, the compiler gives an error. Named constants make programs easier to read and change: to change the value you edit only one line.