Find Type Of Variable In GoLang | Go Language Examples | Java Inspires



 Hi Guys, Welcome to Java Inspires ..

In this post, we will see how to find the type of varible in go language.

goexample.go

package main

import (
	"fmt"
	"reflect"
)

func main() {

	// lets start

	var var1 = 101

	fmt.Println("var1 type :", reflect.TypeOf(var1))

	var var2 = 12.12
	fmt.Println("var2 type :", reflect.TypeOf(var2))

	var var3 = true
	fmt.Println("var3 type :", reflect.TypeOf(var3))

	var var4 = complex(2, 3)

	fmt.Println("var4 type :", reflect.TypeOf(var4))

}

Output:

PS D:\MyCode\go\example> go run .\goexample.go
var1 type : int
var2 type : float64   
var3 type : bool      
var4 type : complex128
PS D:\MyCode\go\example> '


Post a Comment

Previous Post Next Post