C++ Long Long Maximum Value

In C++, a long long is an integer data type that provides support for very large integer values. It is at least 64 bits in size, making it capable of handling significantly larger numbers compared to int or long. The maximum value a long long can represent is 9,223,372,036,854,775,807. This value is defined by the LLONG_MAX macro in the <climits> header.


Maximum 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 maximum limit of a long long data type is 9,223,372,036,854,775,807.


C++ Program to Access Long Long Maximum Value

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

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

main.cpp

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

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

Output

The maximum value of long long is: 9223372036854775807

Explanation

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