I've been using c++ for over 3 months and I can't figure out the exact maximum value of numbers in long long int.
Does anyone know the value?
It depends on the system. The C++ standard only guarantees that the minimum size for long long int will be 64-bits. This is also by far the most common size.
With a 64-bit size, the maximum number that can be represented will be 2^63 - 1, which equals 9223372036854775807. The reason for this exact size, is that we need half of the bit combinations for the negative numbers, then one for 0 and the rest for the positive numbers.
The max value on a specific system can also be checked programmatically with:
#include <iostream>
#include <limits>
int main() {
std::cout << std::numeric_limits<long long int>::max();
}
Output:
9223372036854775807
long long int doesn't have a fixed maximum value specified by C++ language - it depends on the platform.
Use std::numeric_limits<long long>::max() (from <limits> header) to get its maximum value.
signed and unsigned are different though and OP asked for signed.
The guarantee by the C++ Standard for the long long modifier is that it will have a width of at least 64 bits. (see here).
The exact width of the type is, however, dependant on the particular platform, so you might get more thatn 64 bits for your types.
To check the maximum and minimum number a long long inttype can hold on your machine and implementation, use the <limits> library with std::numeric_limits<long long>. You can read more about that here.
std::numeric_limits<long long int>::maxLLONG_MAXalso contains the value.