by Dinesh Thakur Category: Preprocessor Directives

A macro may be used in the definition of another macro as illustrated below.

#define A(x) x*x

#define cost(A,y) A*y

Program illustrates this concept. In this program, Area is a function of x, and the cost of painting the area is defined as a function of area in the macro definition.


#define Area(x) x*x
#define Costpaint(x,y,z) (z*y + Area (x))
void main()
   int A = 8, B= 6, C = 4;
   printf("The area of square= %d\n", Area(A));
   printf("Cost of paint= %d\n", Costpaint(A,B,C));

Nesting of Macros in C

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.