//#define replaces a name with its text before compilation:
//the constant has no type, no memory and no scope
#define MAX_USERS 100
#define PI 3.14159
#define GREETING "Hello"
int maxUsers = MAX_USERS;
//maxUsers is 100
double area = PI * 2 * 2;
//area is 12.56636
const char *greeting = GREETING;
//greeting is "Hello"
//the text is pasted as is: without parentheses
//WIDTH * 2 turns into 10 + 5 * 2
#define WIDTH 10 + 5
int badWidth = WIDTH * 2;
//badWidth is 20
#define HEIGHT (10 + 5)
int goodHeight = HEIGHT * 2;
//goodHeight is 30
//a default value that the build can replace: cc -DBUFFER_SIZE=512
#ifndef BUFFER_SIZE
#define BUFFER_SIZE 256
#endif
char buffer[BUFFER_SIZE];
size_t bufferSize = sizeof buffer;
//bufferSize is 256
//C23: constexpr is a constant with a type, checked by the compiler
constexpr int maxItems = 50;
//maxItems is 50
printf("maxUsers is %d\n", maxUsers);
printf("area is %.5f\n", area);
printf("greeting is %s\n", greeting);
printf("badWidth is %d\n", badWidth);
printf("goodHeight is %d\n", goodHeight);
printf("bufferSize is %zu\n", bufferSize);
printf("maxItems is %d\n", maxItems);