Golang math.MaxUint64 Constant with Examples

Golang | math.MaxUint64 Constant: Here, we are going to learn about the MaxUint64 constant of the math package with its usages, syntax, and examples.
Submitted by IncludeHelp, on August 28, 2021

math.MaxUint64 Constant

The MaxUint64 constant is an inbuilt constant of the math package which is used to get the highest (maximum) value that can be represented by a uint64 (unsigned int64).

The value of math.MaxUint64 constants is 1<<64 - 1 or 18446744073709551615.

Syntax:

int math.MaxUint64

Parameter(s):

  • None

Return Value:

The return type of math.MaxUint64 constant is int, it returns the highest (maximum) value that can be represented by a uint64.

Example 1:

// Golang program to demonstrate the
// example of math.MaxUint64 Constant

package main

import (
	"fmt"
	"math"
)

func main() {
	fmt.Printf("Type of math.MaxUint64 is %T\n", math.MaxUint64)
	fmt.Println("Value of math.MaxUint64:", math.MaxUint64)
}

Output:

The result will be the highest value of a MaxUint64, 
the result may generate int overflow error.

Explanation:

In the above program, we imported the math package to use the math.MaxUint64 constant, then printed the type and value of the math.MaxUint64 constant.

Example 2:

// Golang program to demonstrate the
// example of math.MaxUint64 Constant

package main

import (
	"fmt"
	"math"
)

// creating function to
// return the value of MaxUint64.
func getMaxUint64() int {
	return math.MaxUint64
}

func main() {
	fmt.Println("Value of math.MaxUint64:", getMaxUint64())
}

Output:

The result will be the highest value of a MaxUint64, 
the result may generate int overflow error.

Golang math Package Constants and Functions »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.