std::numeric_limits::max() and std::numeric_limits::min() in C++In this article, we will discuss std::numeric_limits::max() and std::numeric_limits::min() functions with their syntax and examples. What is std::numeric_limits::max()?The std::numeric_limits<T>:: max() method returns the largest finite number that can be represented by the numeric type T. All arithmetic types can work for type T. Header files:Template:Syntax: It has the following syntax: Parameter: It can receive any single type of data, such as T. Return Type: Depending on the type T, it returns predefined macros, true, or the default T(). Program 1:The following program demonstrates the method std::numeric_limits<T>::max(). Filename: MaxLimits.cpp Output: bool limit: 1 char limit: 127 unsigned char limit: 255 short limit: 32767 int: 2147483647 unsigned int limit: 4294967295 long long limit: 9223372036854775807 float limit: 3.40282e+38 double limit: 1.79769e+308size_t limit: 18446744073709551615 What is std::numeric_limits::min()?The std::numeric_limits<T>::min() method returns the smallest finite number that may be represented by the numeric type T. For type T, any limited arithmetic type is valid. Header File:Syntax:It has the following syntax: Parameter: It can receive any single type of data, such as T. Return Type: Depending on the type T, it returns established macros, true or default T(). Min results in the smallest positive normalized value for floating-point numbers types with denormalization. For the floating data type, use numeric_limits::lowest() to identify the value that contains no values smaller than it. Example:Output: bool min value: 0 char min value: -128 unsigned char min value: 0 short min value: -32768 int min value: -2147483648 unsigned int min value: 0 long long min value: -9223372036854775808 float: 1.17549e-38 double min value: 2.22507e-308 size_t min value: 0 |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India