C++ Unsigned Long Long Maximum Value
In C++, an unsigned long long
is an integer data type used to store only non-negative integer values. It provides an extremely large range for positive numbers, making it ideal for scenarios requiring large numerical storage. The size of an unsigned long long
is at least 64 bits, and the maximum value it can represent is 18,446,744,073,709,551,615. This value is defined by the ULLONG_MAX
macro in the <climits>
header.
Maximum Limit of Unsigned Long Long Data Type
The unsigned long long
data type represents numbers in the range:
- Minimum Value: 0
- Maximum Value: 18,446,744,073,709,551,615
The range is derived from the formula:
0 to 2^n - 1
Where n
is the number of bits used by the data type. For an unsigned long long
, n = 64
, resulting in:
0 to 2^64 - 1 = 0 to 18,446,744,073,709,551,615
From this, the maximum limit of an unsigned long long
data type is 18,446,744,073,709,551,615
.
C++ Program to Access Unsigned Long Long Maximum Value
You can programmatically access the maximum value of an unsigned long long
using the ULLONG_MAX
constant from the <climits>
header.
The following example demonstrates how to access and use the maximum value of an unsigned long long
in your programs:
main.cpp
#include <iostream>
#include <climits>
int main() {
// Accessing the maximum value of unsigned long long
std::cout << "The maximum value of unsigned long long is: " << ULLONG_MAX << std::endl;
return 0;
}
Output
The maximum value of unsigned long long is: 18446744073709551615
Explanation
- The
<climits>
header provides macros for the limits of fundamental data types in C++. - The
ULLONG_MAX
macro defines the maximum value of anunsigned long long
, which is18,446,744,073,709,551,615
. - The program uses
std::cout
to output the maximum value of anunsigned long long
directly usingULLONG_MAX
.