VOOZH about

URL: https://www.geeksforgeeks.org/c/c-define-preprocessor/

⇱ #define in C - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

#define in C

Last Updated : 23 Jul, 2025

In C programming, #define is a preprocessor directive that is used to define macros. The macros are the identifiers defined by #define which are replaced by their value before compilation. We can define constants and functions like macros using #define. The generics in C are also implemented using the #define preprocessor directive along with _Generic.

Syntax of C #define

The syntax of #define preprocessor directive in C is:

For Defining Constants

#define MACRO_NAME value

For Defining Expressions

#define MACRO_NAME (expression within brackets)

For Defining Expression with Parameters

Arguments passed in the macros can be used in the expression.

#define MACRO_NAME(ARG1, ARG2,..) (expression within brackets)

There are a few more ways using which we can define macros. To know more, refer to this article - Macros and its types in C

Examples of C #define

Example 1:

In the below example, we have defined a macro 'PI' and assigned it a constant value which we can use later in the program to calculate the area of a circle.


Output
Area of Circle of radius 21: 1385

Example 2:

In the below example, we have defined a macro 'PI' and assigned it an expression, and that value of the expression is used in the program using 'PI'.


Output
Area of Circle of radius 7: 147

Example 3:

In the below example, we have defined two macros CIRCLE_AREA and SQUARE_AREA with a parameter and that parameter is used in the expression to calculate the area of circle and square respectively.


Output
Area of Circle of radius 21: 1384 
Area of square of side 5: 25

Important Points

  • Macros declared using #define are used to store constants and cannot be changed. we cannot assign variables to the macros.
  • We cannot use the '=' operator to assign value to the macros (eg. #define PI 3.14).
  • We do not use the semicolon ';' at the end of the statement in #define.
Comment
Article Tags: