C++ Long Long Minimum Value

In C++, a long long is an integer data type designed to store very large integer values. It is at least 64 bits in size on all systems, providing an extensive range for both positive and negative numbers. The minimum value a long long can represent is -9,223,372,036,854,775,808. This value is defined by the LLONG_MIN macro in the <climits> header.


Minimum Limit of Long Long Data Type

The long long data type represents numbers in the range:

  • Minimum Value: -9,223,372,036,854,775,808
  • Maximum Value: 9,223,372,036,854,775,807

The range is derived from the formula:

-2^(n-1) to 2^(n-1) - 1

Where n is the number of bits used by the data type. For a long long, n = 64, resulting in:

-2^(64-1) to 2^(64-1) - 1 = -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

From this, the minimum limit of a long long data type is -9,223,372,036,854,775,808.


C++ Program to Access Long Long Minimum Value

You can programmatically access the minimum value of a long long using the LLONG_MIN constant from the <climits> header.

The following example demonstrates how to access and use the minimum value of a long long in your programs:

main.cpp

</>
Copy
#include <iostream>
#include <climits>

int main() {
    // Accessing the minimum value of long long
    std::cout << "The minimum value of long long is: " << LLONG_MIN << std::endl;
    return 0;
}

Output

The minimum value of long long is: -9223372036854775808

Explanation

  • The <climits> header provides macros for the limits of fundamental data types in C++.
  • The LLONG_MIN macro defines the minimum value of a long long, which is -9,223,372,036,854,775,808.
  • The program uses std::cout to output the minimum value of a long long directly using LLONG_MIN.