The # and ## operators

Preprocessor

//# turns a macro argument into a string literal
#define STR(x) #x

const char *expression = STR(a + b * 2);
//expression is "a + b * 2"

//# takes the argument as written: a macro in it stays a name.
//A second macro expands the argument first
#define MAX_SIZE 100
#define XSTR(x) STR(x)
const char *name = STR(MAX_SIZE);
//name is "MAX_SIZE"
const char *value = XSTR(MAX_SIZE);
//value is "100"

//## glues two tokens into one name
#define FIELD(n) field##n
int FIELD(1) = 10; //int field1 = 10;
int FIELD(2) = 20; //int field2 = 20;
int sum = field1 + field2;
//sum is 30

//together: a variable is printed with its own name,
//and string literals side by side join into one
#define PRINT_INT(var) printf(#var " is %d\n", var)
int count = 3;
PRINT_INT(count);
//printed "count is 3"

//## builds names of functions from one pattern
int maxInt(int a, int b) {
    return a > b ? a : b;
}
double maxDouble(double a, double b) {
    return a > b ? a : b;
}
#define MAX_OF(type, a, b) max##type(a, b)
int biggerInt = MAX_OF(Int, 3, 7);
//biggerInt is 7
double biggerDouble = MAX_OF(Double, 1.5, 2.5);
//biggerDouble is 2.5

printf("expression is %s\n", expression);
printf("name is %s\n", name);
printf("value is %s\n", value);
printf("sum is %d\n", sum);
printf("biggerInt is %d\n", biggerInt);
printf("biggerDouble is %g\n", biggerDouble);