c / beginner
Snippet
Constants with #define
The #define directive creates a macro, which the preprocessor replaces with the specified value before compilation. It is commonly used for fixed values that shouldn't change.
snippet.c
1
2
3
4
#define MAX_SCORE 100#define PI 3.14159float area = PI * 10 * 10;
Breakdown
1
#define MAX_SCORE 100
Defines a constant named MAX_SCORE with the value 100.
2
float area = PI * 10 * 10;
Uses the defined PI macro in a calculation.