Languages
[Edit]
EN

C++ - minimum and maximum long value

10 points
Created by:
Amir-Hashempur
607

In this short article, we would like to show how to get in C++ minimal and maximal long value.

Quick solution:

// #include <limits>

long min = numeric_limits<long>::min();  // minimum possible value
long max = numeric_limits<long>::max();  // maximum possible value

 

Practical example

In the below example we use numeric_limits API that provides current max and min values.

#include <limits>
#include <iostream>

using namespace std;

int main()
{
    long min = numeric_limits<long>::min();  // minimum possible value
    long max = numeric_limits<long>::max();  // maximum possible value

    cout << "min: " << min << endl;  // min: -9223372036854775808
    cout << "max: " << max << endl;  // max: 9223372036854775807

    return 0;
}

Output:

min: -9223372036854775808
max: 9223372036854775807

 

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join