I am currently taking a C++ course on www.udemy.com In one of the lessons the teacher is using #include <limits>
to demonstrate the maximum number of integers an integer can have. However, when I go to include limits, everything goes well until I try to print INT_MAX and INT_MIN to see the maximum integers and the minimum integers.
Here is my code:
#include <iostream>
#include <limits>
using namespace std;
int main() {
cout << "MaxInt= " << INT_MAX << endl;
cout << "MinInt = " << INT_MIN << endl;
return 0;
}
Side note: I am using Eclipse Neon CDT on Windows 10 with the MinGW Compiler.
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.
The INT_MIN and INT_MAX macros are the C way to get the maximum and minimum values of an int , and are defined in the "climits" header. The "limits" header defines the class template std::numeric_limits , which is the C++ way of getting the range of various types.
INT_MAX is a macro which represents the maximum integer value. Similarly, INT_MIN represents the minimum integer value. These macros are defined in the header file <limits.
You want #include <climits>
or <limits.h>
, not <limits>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With