Most of the times, in competitive programming, there is a need to assign the variable, the maximum or minimum value that data type can hold, but remembering such a large and precise number comes out to be a difficult job. Therefore, C++ has certain macros to represent these numbers, so that these can be directly assigned to the variable without actually typing the whole number.
INT_MAX is a macro that specifies that an integer variable cannot store any value beyond this limit.
INT_MIN specifies that an integer variable cannot store any value below this limit.
Values of INT_MAX and INT_MIN may vary from compiler to compiler. Following are typical values in a compiler where integers are stored using 32 bits. Value of INT_MAX is +2147483647. Value of INT_MIN is -2147483648.
Applications of INT_MAX and INT_MIN :
1. Check for Integer overflow :
Similarly, we can check for overflow while subtracting 2 numbers using INT_MIN.
2. Computing MIN in an array with large elements
We usually assign a high value to MIN to compute minimum value in an array. But if an array has large elements, we must assign the highest possible value to the array.
Below is the C++ implementation :
Similarly, MAX can be found in an array of large numbers using INT_MIN.
This article is contributed by Rohit Thapliyal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- stringstream in C++ and its applications
- MakeFile in C++ and its applications
- Applications of Pointers in C/C++
- C++ String Class and its Applications | Set 2
- C++ string class and its applications
- strchr() function in C++ and its applications
- Reference to a pointer in C++ with examples and applications
- Synchronous Chatting Application using C++ boost::asio
- C/C++ For loop with Examples
- How to input a comma separated string in C++?
- Program to Parse a comma separated string in C++
- Difference between Private and Protected in C++ with Example
- Arrow operator -> in C/C++ with Examples
- Difference between Inheritance and Polymorphism