1
0

mac_arg.c 628 B

123456789101112131415161718192021222324252627
  1. /* mac_arg.c -- macros with arguments */
  2. #include <stdio.h>
  3. #define SQUARE(X) X*X
  4. #define PR(X) printf("The result is %d.\n", X)
  5. int main(void)
  6. {
  7. int x = 5;
  8. int z;
  9. printf("x = %d\n", x);
  10. z = SQUARE(x);
  11. printf("Evaluating SQUARE(x): ");
  12. PR(z);
  13. z = SQUARE(2);
  14. printf("Evaluating SQUARE(2): ");
  15. PR(z);
  16. printf("Evaluating SQUARE(x+2): ");
  17. PR(SQUARE(x+2));
  18. printf("Evaluating 100/SQUARE(2): ");
  19. PR(100/SQUARE(2));
  20. printf("x is %d.\n", x);
  21. printf("Evaluating SQUARE(++x): ");
  22. PR(SQUARE(++x));
  23. printf("After incrementing, x is %x.\n", x);
  24. return 0;
  25. }