Home C-tutorials C define Macro
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

C define Macro

Advertisement
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:

DEFINEMA.C


#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);
  getch();
  return 0;
}

Output will be displayed as:

DEFINEMA.EXE

Download Source Code:

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  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.

Posted on: February 5, 2009

Related Tutorials

Ask Questions?    Discuss: C define Macro  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
ripen sanghvi
March 28, 2011
b.c.a

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.
manisha
September 1, 2011
appreciation.....

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

please illustrate more
bhavya
January 9, 2012
macro

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.
vijendra
September 14, 2011
what is a macros in c lag & uses

excellent
DMCA.com