C examples for Preprocessor:Macro
For example, consider the following formula that computes the area of a rectangle.
Area of a rectangle = length x width
The following code uses macro to calculate the area of a rectangle.
#include <stdio.h> #define AREA(l,w) ( l * w ) /*from w w w.ja va 2 s.c o m*/ int main() { int length = 0; int width = 0; printf("\nEnter length: "); scanf("%d", &length); printf("\nEnter width: "); scanf("%d", &width); printf("\nArea of rectangle = %d\n", AREA(length,width)); }