#define Constants
Use preprocessor constants.
What #define Does
#define is a preprocessor directive that creates a macro: a name the preprocessor replaces with text before compilation.
It is commonly used to give a readable name to a fixed value like a buffer size or a limit.
#define MAX_LEN 256Text Substitution
A macro is pure text replacement. Wherever MAX_LEN appears, the preprocessor writes 256 in its place.
There is no type and no memory; it happens before the compiler even sees the code.
#include <stdio.h>
#define MAX_LEN 256
int main(void) {
printf("%d\n", MAX_LEN);
return 0;
}All lessons in this course
- Defining Enums
- Enum Values and Ranges
- const Variables
- #define Constants