Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • C++ Data Types
  • C++ Input/Output
  • C++ Arrays
  • C++ Pointers
  • C++ OOPs
  • C++ STL
  • C++ Interview Questions
  • C++ Programs
  • C++ Cheatsheet
  • C++ MCQ
  • C++ Projects
  • C++ Exception Handling
  • C++ Memory Management
Open In App
Next Article:
std::numeric_limits::max() and std::numeric_limits::min() in C++
Next article icon

std::numeric_limits::max() and std::numeric_limits::min() in C++

Last Updated : 01 Feb, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

std::numeric_limits::max():

The std::numeric_limits<T>::max() function is used to get the maximum finite value representable by the numeric type T. All arithmetic types are valid for type T.

Header File:

#include<limits>

Template:

static T max() throw();  static constexpr T max() noexcept;

Syntax:

std::numeric_limits<T>::max

Parameter: It receives any one type of data type i.e., T.

Return Type: It returns predefined macros, true or default T() depending on type T. Some standard return values are:

Type Tstd::numeric_limits<T>::max()
/* non-specialized */T()
boolTRUE
charCHAR_MAX
signed charSCHAR_MAX
unsigned charUCHAR_MAX
wchar_tWCHAR_MAX
shortSHRT_MAX
unsigned shortUSHRT_MAX
intINT_MAX
unsigned intUINT_MAX
longLONG_MAX
unsigned longULONG_MAX
long longLLONG_MAX
unsigned long longULLONG_MAX
floatFLT_MAX
doubleDBL_MAX
long doubleLDBL_MAX

Program 1:

Below is the program to illustrate the function std::numeric_limits<T>::max(). The output of the program is system-specific.

C++
// C++ program to illustrate the // function numeric_limits<T>::max #include <iostream> #include <limits> using namespace std;  // Driver Code int main() {     cout << "bool: "          << numeric_limits<bool>::max()          << '\n';      // It returns 127 in ASCII value     // to print in integer that can     // be typecast it to int()     cout << "char: "          << int(numeric_limits<char>::max())          << '\n';      cout << "unsigned char: "          << int(numeric_limits<unsigned char>::max())          << '\n';      cout << "short: "          << numeric_limits<short>::max()          << '\n';      cout << "int: " << numeric_limits<int>::max()          << '\n';      cout << "unsigned int: "          << numeric_limits<unsigned int>::max()          << '\n';      cout << "long long: "          << numeric_limits<long long>::max()          << '\n';      cout << "float: "          << numeric_limits<float>::max()          << '\n';      cout << "double: "          << numeric_limits<double>::max()          << '\n';      cout << "size_t: "          << numeric_limits<size_t>::max()          << '\n'; } 
Output:
  bool: 1  char: 127  unsigned char: 255  short: 32767  int: 2147483647  unsigned int: 4294967295  long long: 9223372036854775807  float: 3.40282e+38  double: 1.79769e+308  size_t: 18446744073709551615  

std::numeric_limits::min():

The std::numeric_limits<T>::min() function is used to get the minimum finite value representable by the numeric type T. All bounded arithmetic types are valid for type T.

Header File:

#include<limits>

Template:

static T min() throw();  static constexpr T min() noexcept;

Syntax:

std::numeric_limits<T>::min

Parameter: It receives any one type of data type i.e., T.

Return Type: It returns predefined macros, true or default T() depending on type T. For floating-point types with denormalization, min returns the minimum positive normalized value. To find the value that has no values less than it for floating data type, use numeric_limits::lowest().  Some standard return values are:

Type Tstd::numeric_limits::min()
/* non-specialized */T()
boolFALSE
charCHAR_MIN
signed charSCHAR_MIN
unsigned char​0​
wchar_tWCHAR_MIN
shortSHRT_MIN
unsigned short0
intINT_MIN
unsigned int0
longLONG_MIN
unsigned long0
long longLLONG_MIN
unsigned long long​0​
floatFLT_MIN
doubleDBL_MIN
long doubleLDBL_MIN

Program 2:

Below is the program to illustrate the function std::numeric_limits<T>::min(). The output of the program is system-specific.

C++
// C++ program to illustrate the // function numeric_limits<T>::min #include <iostream> #include <limits> using namespace std;  // Driver Code int main() {     cout << "bool: "          << numeric_limits<bool>::min()          << '\n';      // numeric_limits<char>:: min()     // returns 127 in ASCII value in     // integer that can be typecast     // to int()     cout << "char: "          << int(numeric_limits<char>::min())          << '\n';      cout << "unsigned char: "          << int(numeric_limits<unsigned char>::min())          << '\n';      cout << "short: "          << numeric_limits<short>::min() << '\n';      cout << "int: " << std::numeric_limits<int>::min()          << '\n';     cout << "unsigned int: "          << numeric_limits<unsigned int>::min()          << '\n';      cout << "long long: "          << numeric_limits<long long>::min()          << '\n';     cout << "float: "          << numeric_limits<float>::min()          << '\n';      cout << "double: "          << numeric_limits<double>::min()          << '\n';      cout << "size_t: "          << numeric_limits<size_t>::min()          << '\n'; } 
Output:
  bool: 0  char: -128  unsigned char: 0  short: -32768  int: -2147483648  unsigned int: 0  long long: -9223372036854775808  float: 1.17549e-38  double: 2.22507e-308  size_t: 0  

Next Article
std::numeric_limits::max() and std::numeric_limits::min() in C++

S

scorchingeagle
Improve
Article Tags :
  • C++ Programs
  • C++
Practice Tags :
  • CPP

Similar Reads

    Difference between std::numeric_limits<T> min, max, and lowest in C++
    The std::numeric_limits<T> class in the limit header provides min(), max(), and lowest() function for all numeric data types along with the other member functions. std::numeric_limits<T>::max(): The std::numeric_limits<T>::max() for any type T gives the maximum finite value represe
    5 min read
    Find Maximum and Minimum Element in a Set in C++ STL
    In C++, set stores the unique elements in sorted order so it is pretty straightforward to find the minimum and maximum values. In this article, we will learn different methods to find the minimum and maximum values in a set in C++.As the set is sorted, the most efficient way to find the minimum and
    3 min read
    Data types that supports std::numeric_limits() in C++
    The numeric_limits class template provides an easy and standardized way to query various properties of arithmetic types. For example, the maximum value a type T can store is std::numeric_limits<T>::max(). Example: std::numeric_limits<int>::max() gives the maximum possible value we can st
    8 min read
    How to Find the Smallest Number in an Array in C++?
    In C++, arrays are the data types that store the collection of the elements of other data types such as int, float, etc. In this article, we will learn how to find the smallest number in an array using C++. For Example,Input: myVector = {10, 3, 10, 7, 1, 5, 4} Output: Smallest Number = 1Find the Sma
    2 min read
    How to Find the Range of Numbers in an Array in C++?
    The range of numbers in an array means the difference between the maximum value and the minimum value in the given array. In this article, we will learn how to find the range of numbers in an array in C++. For Example, Input: myArray = {5,10,15,30,25}; Output: Range: 25Range Within an Array in C++To
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences