Constants, macros, enums in C
The several ways C names a fixed value.
#define MAX_USERS 100
#define SQUARE(x) ((x) * (x))
enum Direction { NORTH, EAST, SOUTH, WEST };
int capacity(void) {
const int base = 10;
enum Direction heading = EAST;
int area = SQUARE(base);
return area + MAX_USERS + heading;
}
How it works
#definesubstitutes text before compiling.- A function-like macro like
SQUAREinlines an expression. enumnames a set of related integer constants.
Keywords and builtins used here
capacityconstenumintreturnvoid
The run, in numbers
- Lines
- 11
- Characters to type
- 233
- Tokens
- 50
- Three-star pace
- 80 tpm
At the three-star pace of 80 tokens a minute, this run takes about 38 seconds.
Step 3 of 7 in Variables & types, step 3 of 35 in Language basics.