Home C-tutorials C define Macro



C define Macro
Posted on: February 5, 2009 at 12:00 AM
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:

Related Tags for C define Macro:
cmacideantmacrosiosedmacrowordconstconstantsexpressionkeystatekeywordsssoiddefineifiekeywordwithconstantexpressionsstatementtoexpresscissiwordseitdirectiveociuseulidentifierinasstamntososesemdirmemeanidentifiersstatementssrectsodirectessatkisirhaivpresspreeaandarstatconssocreprrdsxpssrdthstassociateantshatfinidentidentprndono


More Tutorials from this section

Ask Questions?    Discuss: C define Macro  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.