Skip to content
Related Articles

Related Articles

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

In this article, we will discuss the long long int data type in C++. long long int data type in C++ is used to store 64-bit integers. It is one of the largest data types to store integer values, unlike unsigned long long int both positive as well as negative.

Some properties of the long long int data type are:

  • Being a signed data type, it can store positive values as well as negative values.
  • Takes a size of 64 bits where 1 bit is used to store the sign of the integer.
  • A maximum integer value that can be stored in a long long int data type is typically 9, 223, 372, 036, 854, 775, 807 around 263 – 1(but is compiler dependent).
  • The maximum value that can be stored in long long int is stored as a constant in <climits> header file. Whose value can be used as LLONG_MAX.
  • A minimum integer value that can be stored in a long long int data type is typically –9, 223, 372, 036, 854, 775, 808, around –263 (but is compiler dependent).
  • In case of overflow or underflow of data type, the value is wrapped around. For example, if –9, 223, 372, 036, 854, 775, 808 is stored in an long long int data type and 1 is subtracted from it, the value in that variable will become equal to 9, 223, 372, 036, 854, 775, 807. Similarly, in the case of overflow, the value will round back to –9, 223, 372, 036, 854, 775, 808.

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

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate the maximum
// value that can be stored in long long int
#include <climits>
#include <iostream>
using namespace std;
  
// Driver Code
int main()
{
    // From the constant of climits
    // header file
    long long int valueFromLimits = LLONG_MAX;
    cout << "Value from climits "
         << "constant (maximum): ";
    cout << valueFromLimits
         << "\n";
  
    valueFromLimits = LLONG_MIN;
    cout << "Value from climits "
         << "constant (minimum): ";
    cout << valueFromLimits
         << "\n";
  
    return 0;
}

chevron_right


Output:

Value from climits constant (maximum): 9223372036854775807
Value from climits constant (minimum): -9223372036854775808

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 :