What is the maximum value a int can make?

Hi, just asking as a beginner in c++, what is the maximum value you can declare in int?
Last edited on
you could cheat and get it using unsigned int ;)
but there is also a c++ header file containing that information :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Example program
#include <iostream>
#include <limits>

int main()
{
    // the cheating way
    unsigned int i = -1;
    std::cout << "unsigned int max: " << i << '\n';
    std::cout << "int max: " << i / 2 << "\n\n";
    
    // the c++ way
    std::cout << "unsigned int max: " << std::numeric_limits<unsigned int>::max() << '\n';
    std::cout << "int max: " << std::numeric_limits<int>::max() << '\n';
}
Last edited on
closed account (48T7M4Gy)
http://www.cplusplus.com/reference/limits/numeric_limits/

Try the sample program towards the end of this article. By inserting the different types eg <float> instead of <int> you can find out to your hearts content.
Lol, I need the truth on what's the maximum value a int can declare, anyway, that could be interesting :) Thanks for the reply ..
closed account (48T7M4Gy)
Run the program for the reasons given in the article - it is system dependent. What's the difficulty in pressing a the gear wheel ? Either that or google it.
closed account (48T7M4Gy)
Oy vez

http://lmgtfy.com/?q=what+is+the+maximum+value+you+can+declare+in+int%3F+
Last edited on
I need the truth on what's the maximum value a int can declare

That's system dependent...

in general the max-value of an int is (2^(n-1)) - 1
on 32-bit operating systems it's (2^31)-1
on 64 bit operat it's (2^63)-1
Last edited on
Topic archived. No new replies allowed.