Overflow/Underflow in C++?

I've been wondering for quitesome time about the set limits of positive and negative integer values for c++, I'm working on a project right now and It would be nice to know that info before I go head on the program. Thanks in advance for the help. 

From Wikipedia ( https://en.wikipedia.org/wiki/C_variable_types_and_declarations#Size )

int/signed int: basic signed integer type. At least 16 bits in size.

That means we have at least 2^16 possible values, minus the one bit for signed-ness (which is always taken from the positive range). min: -32768, max: 32767.

But once again, this is the minimum. If you need to know the range you use the header stdint.h (c) or cstdint (c++).

It depends on your system. As wick pointed out, 16 bit is the lowest you can get.

If you've got a 32 bit system, it will most likely have 32 bit integers. Meaning that the maximum integer will be 2^32 = 4,294,967,296.

The same will go for a 64 bit system, 2^64 = 1.8446744e+19.

Basically, if you want your code to be portable between all sorts of computers, you shouldn't go higher/lower than what a 16 bit computer can handle (32767).

It can even vary slightly from computer to computer even if they're both 32 bit.

Use an integer of type long to use the maximum number of bits available. If that's still not long enough, you'll have to create your own number class, with which you can perform mathematical operations on.

Use an integer of type long to use the maximum number of bits available

Actually, no. long long might hold more bits.

Also, certain api's have built in numbers guaranteed to be so many bits. 

 

Basically, use ints for everything non decimal and floats for everything that does division or decimal. For large calculations, use a long or "long long" / double or long double. 

It depends on your CPU's Assembler, your OS, your compiler, and your code itself. Your code travels backwards through those levels before it's broken down to 1's and 0's. Understanding binary may help you see why 16-bit uses 2^16 and 32-bit uses 2^32 as limits.

http://stackoverflow.com/questions/589575/size-of-int-long-etc/589684#589684