Home > Article > Backend Development > How to use min function in c++
The min() function in C returns the minimum of two or more values. It is a generic function that can compare values of different types. Usage is as follows: Compare two values: min(a, b) Compare multiple values: min(a, b, c) Compare values of different types: min(a, b, c) (need to specify the type explicitly) Applicable to Comparison of elements in arrays and containers
min() function in C
min() function is used Returns the minimum of two or more values. It is a generic function that can be used to compare values of different types.
Syntax
<code class="cpp">template <typename T> T min(T a, T b); template <typename T> T min(T a, T b, T c); ...</code>
Where, T
is the type of the value to be compared.
Usage
<code class="cpp">int x = min(5, 10); // x = 5</code>
<code class="cpp">int y = min(5, 10, 15); // y = 5</code>
<code class="cpp">double z = min(5.5, 10.0); // z = 5.5</code>
Note
std::string::compare()
function. The above is the detailed content of How to use min function in c++. For more information, please follow other related articles on the PHP Chinese website!