max (C++)
Go Up to stdlib.h Index
Header File
stdlib.h
Category
C++ Prototyped Routines
Prototype
(type) max(a, b);
template <class T> T max( T t1, T t2 ); // C++ only
Description
Returns the larger of two values.
The C macro and the C++ template function compare two values and return the larger of the two. Both arguments and the routine declaration must be of the same type.
Return Value
max returns the larger of two values.
Example
#include <stdlib.h> #include <stdio.h> #ifdef __cplusplus int max (int value1, int value2); int max(int value1, int value2) { return ( (value1 > value2) ? value1 : value2); } #endif int main(void) { int x = 5; int y = 6; int z; z = max(x, y); printf("The larger number is %d\n", z); return 0; }
Portability
POSIX | Win32 | ANSI C | ANSI C++ |
---|---|---|---|
+ |