Identify Variable type and values in go lang

package main
import "fmt"
func main() {
var name string = "Mahesh"
age := 25
price := 300.40
fmt.Printf("%T %v\n",name,name)
fmt.Printf("%T %v\n",age,age)
fmt.Printf("%T %v\n",price,price)


string Mahesh
int 25
float64 300.4


  1. In the above program snippet, we use Printf() function of fmt package to print the formatted output.
  2. Withing the Printf( ) %T and %v is called format specifier which represents the output format.
  3. %T represents the Type, which prints the variable type
  4. %v represents the variable's value.
  5. age := 25, creates a variable age with the short variable declaration and assign the value 25. In this case, the variable automatically receives the type and here age is the type of int.
  6. price:=300.40, In this statement price, is created of type float64 because float64 is the default type of floating values in go lang. To create a float32 type variable you need to create a variable as given below. 
  7. \n is called escape sequence which changes the line.
  8. Escape sequences are some not printable characters that handle specially and starts with a backslash (\). \n called newline which changes the line and \t is called tab which prints the tab equivalent space.
var price float32 = 300.40


Popular posts from this blog

Program to calculate telephone bill

Sum of two numbers in go lang

Program to check a year is leap year or not.

String in golang


Arrays in C Language

Reserved Words in Java

Data types in Java

Pointers in C Language

Literals in Java