Example 1 — const, #define, and enum together
Three ways to name a fixed number.
#include <stdio.h>
#define MAX_USERS 100
enum { COLS = 4 };
int main(void) {
const double PI = 3.14159;
double radius = 2.0;
int grid[COLS] = {1, 2, 3, 4};
printf("limit: %d\n", MAX_USERS);
printf("area: %.2f\n", PI * radius * radius);
printf("cols: %d, last: %d\n", COLS, grid[COLS - 1]);
return 0;
} How It Works
MAX_USERSis replaced by100before compilation.PIis a real object; assigning to it is a compile error.COLSis anenumconstant, so it can size an array.
