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 email@example.com. 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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- C++ string class and its applications
- C++ String Class and its Applications | Set 2
- stringstream in C++ and its applications
- Reference to a pointer in C++ with examples and applications
- MakeFile in C++ and its applications
- strchr() function in C++ and its applications
- Applications of Pointers in C/C++
- Pointers in C and C++ | Set 1 (Introduction, Arithmetic and Array)
- fesetround() and fegetround() in C++ and their application
- Lex program to take input from file and remove multiple spaces, lines and tabs
- Queries to insert, delete one occurrence of a number and print the least and most frequent element
- Get first and last elements from Array and Vector in CPP
- Similarities and Differences between Ruby and C language
- Code Optimization Technique (logical AND and logical OR)
- Similarities and Differences between Ruby and C++
- Generate an array of given size with equal count and sum of odd and even numbers
- Similarities and Difference between Java and C++
- Getting System and Process Information Using C Programming and Shell in Linux
- Difference and Similarities between PHP and C
- What are the differences between bitwise and logical AND operators in C/C++?
Improved By : shubhamsonisoni852