min -- Return Lesser of Two Values

Format

#include <stdlib.h>
type min(type a, type b);

Language Level: Extension
min compares two values and determines the smaller of the two. The data type can be any arithmetic data type, signed or unsigned. The type must be the same for both arguments to min.

Note: Because min is a macro, if the evaluation of the arguments contains side effects (post-increment operators, for example), the results of both the side effects and the macro will be undefined.

Return Value
min returns the smaller of the two values.

Example
This example prints the smaller of the two values, a and b.

#include <stdlib.h>
#include <stdio.h>
int main(void)
{
   int a = 10;
   int b = 21;
   printf("The smaller of %d is %d/n", a, b, min(a, b));
   return 0;
   /*****************************************************
      The output should be:
      The smaller of 10 and 21 is 10
   *****************************************************/
}



max -- Return Larger of Two Values
<stdlib.h>