C - Constants
Constants represent values that should not change.
Ways to Define Constants
- constvariables (type-safe):- const int MAX = 100;
- Preprocessor macros (no type checking): #define MAX 100
Examples
#include <stdio.h>
#define BUFFER 1024
const double PI = 3.141592653589793;
int main(void) {
  printf("%d %.2f\n", BUFFER, PI);
}
Common Pitfalls
- Writing to a constvariable (compiler error).
- Macros lack scope and type safety; prefer constwhen possible.