Golang ProgramsGolang Programs

How to print struct variables data?

Below is a short example to print or display the struct variables data in console. You can Print with or without Variable Name for that use %v+ or %v respectively.
package main

import "fmt"

type Employee struct {
	Id int64
	Name string
}

func main() {
	emp := Employee{Id:1200, Name: "Mark Taylor"}
	fmt.Printf("%+v\n",emp)	// Print with Variable Name
	fmt.Printf("%v\n",emp)	// Without Variable Name
	fmt.Printf("%d\n",emp.Id)
	fmt.Printf("%s\n",emp.Name)
}
C:\golang\codes>go run example28.go
{Id:1200 Name:Mark Taylor}
{1200 Mark Taylor}
1200
Mark Taylor

C:\golang\codes>