Share on Google+Share on Google+

C define Macro

Macros are the identifiers that represent statements or expressions.

C define Macro


This section illustrates you how to use macros in C.

Macros are the identifiers that represent statements or expressions. To associate meaningful identifiers with constants, keywords, and statements or expressions,  #define directive is used. You can see in the given example, we have define a macro i.e SQUARE(x) x*x. Here the macro determines the square of the given number.

Macro Declaration:   #define name text

Here is the code:


#include <stdio.h>
#include <conio.h>
#define SQUARE(xx*x
int main() {
  int i = 2;
  int j= SQUARE(i);
  printf("The value of j is: %d\n", j);
  return 0;

Output will be displayed as:


Download Source Code:


Posted on: February 5, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: C define Macro  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
ripen sanghvi
March 28, 2011

its awesum sites. It helped Me so much that i could complete my hardest practicals and assignments... Thanxxx to rose india... Plzzzz b always with me.
September 1, 2011

Good job all you guys amazing tutorial!
anshuman upadhyay
December 9, 2011

please illustrate more
January 9, 2012

what is the difference between defining macro before header files and after header files.
Sandeep Ayipilla
June 7, 2012
Request for give me some more examples

Hi, It is very useful to me, and if you will have given some more examples regarding to this topic, it would be more helpful to me.
September 14, 2011
what is a macros in c lag & uses