0Pricing
C Academy · Lesson

#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 256

Text 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

  1. Defining Enums
  2. Enum Values and Ranges
  3. const Variables
  4. #define Constants
← Back to C Academy