Home »
Golang »
Golang Reference
Golang math.MaxInt32 Constant with Examples
Golang | math.MaxInt32 Constant: Here, we are going to learn about the MaxInt32 constant of the math package with its usages, syntax, and examples.
Submitted by IncludeHelp, on August 28, 2021
math.MaxInt32 Constant
The MaxInt32 constant is an inbuilt constant of the math package which is used to get the highest (maximum) value that can be represented by an int32.
The value of math.MaxInt32 constants is 1<<31 - 1 or 2147483647.
Syntax
int math.MaxInt32
Parameters
Return Value
The return type of math.MaxInt32 constant is int, it returns the highest (maximum) value that can be represented by an int32.
Example 1
// Golang program to demonstrate the
// example of math.MaxInt32 Constant
package main
import (
"fmt"
"math"
)
func main() {
fmt.Printf("Type of math.MaxInt32 is %T\n", math.MaxInt32)
fmt.Println("Value of math.MaxInt32:", math.MaxInt32)
}
Output:
Type of math.MaxInt32 is int
Value of math.MaxInt32: 2147483647
Explanation:
In the above program, we imported the math package to use the math.MaxInt32 constant, then printed the type and value of the math.MaxInt32 constant.
Example 2
// Golang program to demonstrate the
// example of math.MaxInt32 Constant
package main
import (
"fmt"
"math"
)
// creating function to
// return the value of MaxInt32.
func getMaxInt32() int {
return math.MaxInt32
}
func main() {
fmt.Println("Value of math.MaxInt32:", getMaxInt32())
}
Output:
Value of math.MaxInt32: 2147483647
Golang math Package Constants and Functions »