Use Macro to get the bigger int value : Macro Function « Macro Preprocessor « C / ANSI-C






Use Macro to get the bigger int value

#include <stdio.h>

#define MAX(i, j) i>j ? i : j

int main(void)
{
  printf("%d\n", MAX(3, 2));
  printf("%d\n", MAX(1, -1));

  /* this statement does not work correctly */
  printf("%d\n", MAX(100 && -1, 0));

  return 0;
}


           
       








Related examples in the same category

1.Defining a macro to compare two valuesDefining a macro to compare two values
2.Defining a macro to output the value of an expressionDefining a macro to output the value of an expression
3.Generate a square tableGenerate a square table
4.Define small function in macro
5.Make string
6.Use marco for small function
7.Use macro to find the minor variable
8.Define Macro as simple function
9.Use Macro to check the int range