Skip to content
Related Articles

Related Articles

Maximum value of unsigned long long int in C++
  • Last Updated : 03 Dec, 2020

In this article, we will discuss the unsigned long long int data type in C++. It is the largest (64 bit) integer data type in C++

Some properties of the unsigned long long int data type are:

  • An unsigned data type stores only positive values.
  • It takes a size of 64 bits.
  • A maximum integer value that can be stored in an unsigned long long int data type is 18, 446, 744, 073, 709, 551, 615, around 264 – 1(but is compiler dependent).
  • The maximum value that can be stored in unsigned long long int is stored as a constant in <climits> header file whose value can be used as ULLONG_MAX.
  • The minimum value that can be stored in unsigned long long int is zero.
  • In case of overflow or underflow of data type, the value is wrapped around. For example, if 0 is stored in an unsigned long long int data type and 1 is subtracted from it, the value in that variable will become equal to 18, 446, 744, 073, 709, 551, 615. Similarly, in the case of overflow, the value will round back to 0.

Below is the program to get the highest value that can be stored in unsigned long long int in C++:

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to obtain the maximum
// value stored in unsigned long long int
#include <climits>
#include <iostream>
using namespace std;
  
// Driver Code
int main()
{
  
    // From the constant of climits
    // header file
    unsigned long long int valueFromLimits = ULLONG_MAX;
  
    cout << "Value from climits "
         << "constant: ";
    cout << valueFromLimits << "\n";
  
    // Using the wrap around property
    // of data types
  
    // Initialize a variable with value 0
    unsigned long long int value = 0;
  
    // Subtract 1 from value since an
    // unsigned data type cannot store
    // negative number, the value will
    // wrap around  and stores maximum
    // value stored in it
    value = value - 1;
    cout << "Value using the wrap"
         << " around property: "
         << value << "\n";
  
    return 0;
}

chevron_right


Output:

Value from climits constant: 18446744073709551615
Value using the wrap around property: 18446744073709551615

Attention reader! Don’t stop learning now. Get hold of all the important C++ Foundation and STL concepts with the C++ Foundation and STL courses at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up
Recommended Articles
Page :