Golang strconv.IntSize Constant with Examples

Golang | strconv.IntSize Constant: Here, we are going to learn about the IntSize constant of the strconv package with its usages, syntax, and examples.
Submitted by IncludeHelp, on September 05, 2021

strconv.IntSize Constant

The IntSize constant is an inbuilt constant of the strconv package which is used to get the size in bits of an int or uint value. The size of an int or uint depends on the compiler (machine) architecture, by using the IntSize constant we can get it.

Syntax:

int strconv.IntSize

Parameter(s):

  • None

Return Value:

The return type of strconv.IntSize constant is an int, it returns the size in bits of an int or uint value.

Example 1:

// Golang program to demonstrate the
// example of strconv.IntSize Constant

package main

import (
	"fmt"
	"strconv"
)

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

Output:

Type of strconv.IntSize is int
Value of strconv.IntSize: 64

Explanation:

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

Example 2:

// Golang program to demonstrate the
// example of strconv.IntSize Constant

package main

import (
	"fmt"
	"strconv"
)

// creating function to return
// the value of IntSize.
func getIntSize() int {
	return strconv.IntSize
}

func main() {
	fmt.Println("Value of strconv.IntSize:", getIntSize())
}

Output:

Value of strconv.IntSize: 64

Golang strconv Package »





Comments and Discussions!

Load comments ↻






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