MAX - Man Page

maximum or minimum of two values


#include <sys/param.h>

MAX(a, b);
MIN(a, b);


These macros return the maximum or minimum of a and b.

Return Value

These macros return the value of one of their arguments, possibly converted to a different type (see Bugs).


These macros may raise the "invalid" floating-point exception when any of the arguments is NaN.

Conforming to

These nonstandard macros are present in glibc and the BSDs.


If either of the arguments is of a floating-point type, you might prefer to use fmax(3) or fmin(3), which can handle NaN.

The arguments may be evaluated more than once, or not at all.

Some UNIX systems might provide these macros in a different header, or not at all.


Due to the usual arithmetic conversions, the result of these macros may be very different from either of the arguments. To avoid this, ensure that both arguments have the same type.


#include <stdio.h>
#include <stdlib.h>
#include <sys/param.h>

main(int argc, char *argv[])
    int a, b, x;

    if (argc != 3) {
        fprintf(stderr, "Usage: %s <num> <num>\n", argv[0]);

    a = atoi(argv[1]);
    b = atoi(argv[2]);
    x = MAX(a, b);
    printf("MAX(%d, %d) is %d\n", a, b, x);


See Also

fmax(3), fmin(3)


This page is part of release 5.13 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at

Referenced By

The man page MIN(3) is an alias of MAX(3).

2020-11-01 Linux Programmer's Manual