×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang math.MaxUint Constant with Examples

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

math.MaxUint Constant

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

The value of math.MaxUint constants is 1<<intSize - 1.

Note: intSize depends on the machine architecture. For example, if the machine is a 32-bit machine, intSize will be 4 bytes and if the machine is 64-bit, intSize will be 8 bytes.

Syntax

int math.MaxUint

Parameters

  • None

Return Value

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

Example 1

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

package main

import (
	"fmt"
	"math"
)

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

Output:

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

Explanation:

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

Example 2

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

package main

import (
	"fmt"
	"math"
)

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

func main() {
	fmt.Println("Value of math.MaxUint:", getMaxUint())
}

Output:

The result will be the highest value of a uint, 
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.