Integer Limits

Is INT_MAX 1e9?

No. INT_MAX is usually 2,147,483,647, while 1e9 is one billion, a double literal that fits inside a 32-bit int. Here is how to check both values.

On this page
  1. Short answer
  2. What INT_MAX is
  3. Why 1e9 gets mistaken for it
  4. Check it in code
  5. Why 1e9 is a common stand-in
  6. When the limit is different

Short answer

No. On most current systems, INT_MAX is 2,147,483,647, the largest value a 32-bit int can hold. The literal 1e9 means 1,000,000,000, which is less than half of that. The two numbers are not equal.

What INT_MAX is

INT_MAX is defined in <climits> as the largest value an int can store. The C++ standard only guarantees that it is at least 32,767. On common 32-bit platforms it is 2,147,483,647, which is 2^31 - 1. On a platform with a 16-bit int, it would be 32,767. The lower end of the range is covered in the minimum int value in C++.

Why 1e9 gets mistaken for it

Round numbers like this are easy to read as limits, and people often use them as stand-ins for a very large value. The literal 1e9 is written in scientific notation, so the compiler reads it as a floating-point value of type double, not an int. For more on that type, see what does double do in c.

When the value is stored in an int, it is converted. Because 1,000,000,000 is a whole number that fits in a 32-bit int, nothing is lost.

Check it in code

The program below prints INT_MAX and compares it with 1e9:

#include <climits>
#include <iostream>

int main() {
    std::cout << "INT_MAX: " << INT_MAX << '\n';
    std::cout << "INT_MAX == 1e9: " << std::boolalpha << (INT_MAX == 1e9) << '\n';
}

On a platform with a 32-bit int, the output is:

INT_MAX: 2147483647
INT_MAX == 1e9: false

std::numeric_limits<int>::max() from <limits> returns the same value as INT_MAX.

Why 1e9 is a common stand-in

In competitive programming and in code that needs an “infinity” value, 1e9 is a common choice. It is large enough for most inputs, and it leaves room to add two of them without overflow:

const int INF = 1e9;
int total = INF + INF;  // 2000000000, still fits in a 32-bit int

Two values of 1,000,000,000 add up to 2,000,000,000, which is below INT_MAX. Adding a third would give 3,000,000,000, which overflows. Declaring the constant const (see c const keyword) keeps it from being changed by accident.

When the limit is different

INT_MAX is not one number everywhere. On a platform with a narrower int, 1e9 would not fit at all, and converting it would be undefined behavior. To check your own system, print INT_MAX as shown above, or use std::numeric_limits<int>::max() from <limits>.

The complete guide to integer limits

The Minimum Int Value in C++
Read the guide

Keep exploring

Guides from other topics

All topics →

Recursive Functions in C++

A recursive function calls itself to solve smaller parts of a problem. Learn the base case, the recursive case, examples in C++ and when to use recursion.

Recursion 5 min read

The const Keyword in C++

Learn what the const keyword does in C++, how it applies to variables, pointers, references and member functions, and how the compiler enforces it.

const 5 min read