TechArena Community The max() in C++

#1
06-03-2010
 Member Join Date: Dec 2009 Posts: 28
The max() in C++

I am the student of the BSC. I have the knowledge of the C++ language. I can also have the knowledge of the functions of the C++ language. I want to know about the max() function of the C++ language. So, I would like to know how can I use the max() function in the C++ language. Can you have the information on the max() function of the C++ language.
#2
06-03-2010
 Member Join Date: Oct 2005 Posts: 2,389
The max() in C++

According to my knowledge about the max() function that The max() function can be used for to find out the minimum character between the defined two values. The following can be the general syntax of the max() function :
Code:
```template <class S> const S& max ( const S& p, const S& q );
template <class S, class Cmpr>
const S& max ( const S& p, const S& q, Cmpr cmp );```
#3
06-03-2010
 Member Join Date: May 2008 Posts: 2,383
Re: The max() in C++

The following code of lines can illustrates you about the working and the implementation of the max() function of the C++ language :
Code:
```#include <iostream>
#include <algorithm>
using namespace std;
int main ()
{
cout << "max(3,4)==" << max(3,4) << endl;
cout << "max(4,3)==" << max(4,3) << endl;
cout << "max('b','d')==" << max('b','d') << endl;
cout << "max(3.14,2.72)==" << max(3.14,2.72) << endl;
return 0;
}```
Output:
Code:
```max(3,4)==4
max(4,3)==4
max('b','d')==d
max(3.14,2.73)==3.14```
__________________
The FIFA Manager 2009 PC Game
#4
06-03-2010
 Member Join Date: Feb 2008 Posts: 1,848
Re: The max() in C++

The following can be the parameters of the max() function of the C++ language :
1. cmp : This parameter of the max() function can contains an object of the comparison function that can be taking two different values of the equivalent type and can returns the true value if the first argument can be considered less than the second and else returns the false value.
2. p, q : These can be the parameters of the max() function that can contains an items to compare. S can be any type that can be supporting copy constructions and comparisons with an less than operator.
#5
06-03-2010
 Member Join Date: Jan 2008 Posts: 1,515
Re: The max() in C++

The program that can be mentioned below illustrates you about how to use the max() function in the C++ language programming :
Code:
```#include <iostream>
using std::cout;
using std::endl;
#include <algorithm>
int main()
{
cout << "\nThe maximum of 'E' and 'Y' is: " << std::max( 'E', 'Y' );
cout << "\nThe maximum of 21 and 8 is: " << std::max( 21, 8 );
cout << endl;
return 0;
}```
OUTPUT :
Code:
```The maximum of 'E' and 'Y' is: Y
The maximum of 21 and 8 is: 21```
#6
06-03-2010
 Member Join Date: Apr 2008 Posts: 1,948
Re: The max() in C++

The max() function of the C++ language can returns the maximum an argument of among the two given an arguments. The max() function of the C++ language can returns the maximum of the p and q. The comparison can uses an operator "<" (q<p) for the first version and cmp for the second version. The behavior of max() function template can be similar to the following as :
Code:
```template <class S> const S& max ( const S& p, const S& q )
{
return (q<p)?p:q;
}```

 Tags: