How to get the minimum and maximum of the Integer type?

Let’s compare the ways to get the minimum and maximum of the Integer type. Are there any similarities? Which programming language makes it easier?

C++

#include <stdio.h>
#include <limits.h>

int main() {
    printf("Minimum Integer Value: %d\n", INT_MIN);
    printf("Maximum Integer Value: %d\n", INT_MAX);

    return 0;
}

// Output:
// Minimum Integer Value: -2147483648
// Maximum Integer Value: 2147483647

You can check this out in C++ Online Compiler.

Java

class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Minimum Integer Value: " + Integer.MIN_VALUE);
        System.out.println("Maximum Integer Value: " + Integer.MAX_VALUE);
    }
}

// Output:
// Minimum Integer Value: -2147483648
// Maximum Integer Value: 2147483647

You can check this out in Java Online Compiler.

Kotlin

fun main() {
    println("Minimum Integer Value: " + Int.MIN_VALUE)
    println("Maximum Integer Value: " + Int.MAX_VALUE)
}

// Output:
// Minimum Integer Value: -2147483648
// Maximum Integer Value: 2147483647

You can check this out in Kotlin Playground.

PHP

<?php

printf("Minimum Integer Value: %d\n", PHP_INT_MIN);
printf("Maximum Integer Value: %d\n", PHP_INT_MAX);

// Output for 32-bit systems:
// Minimum Integer Value: -2147483648
// Maximum Integer Value: 2147483647
//
// Output for 64-bit systems:
// Minimum Integer Value: -9223372036854775808
// Maximum Integer Value: 9223372036854775807

You can check this out in PHP Online Editor.

Please be aware that values of the following constants in PHP are system-dependent:

PHP_INT_MAX (int)

The largest integer supported in this build of PHP. Usually int(2147483647) in 32 bit systems and int(9223372036854775807) in 64 bit systems.

PHP_INT_MIN (int)

The smallest integer supported in this build of PHP. Usually int(-2147483648) in 32 bit systems and int(-9223372036854775808) in 64 bit systems. Usually, PHP_INT_MIN === ~PHP_INT_MAX.

Source: https://www.php.net/manual/en/reserved.constants.php