1)
package main
/* https://golang.org/pkg/fmt/ */
import (
"fmt"
)
/*A struct is a type which contains named fields.
Define new type named 'Person'*/
type Person struct {
name string
age int
}
func main() {
/*initialize a struc.
Create an instance of type 'Person'*/
p := Person{"Sam", 20}
fmt.Println("====", p)
/* %v print the value in a default format*/
fmt.Printf("=====%v \n", p)
/*With field name*/
fmt.Printf("======%+v \n", p)
/*With type and field name*/
/* %#v a Go-syntax representation of the value*/
fmt.Printf("=======%#v \n", p)
}
package main
/* https://golang.org/pkg/fmt/ */
import (
"fmt"
)
/*A struct is a type which contains named fields.
Define new type named 'Person'*/
type Person struct {
name string
age int
}
func main() {
/*initialize a struc.
Create an instance of type 'Person'*/
p := Person{"Sam", 20}
fmt.Println("====", p)
/* %v print the value in a default format*/
fmt.Printf("=====%v \n", p)
/*With field name*/
fmt.Printf("======%+v \n", p)
/*With type and field name*/
/* %#v a Go-syntax representation of the value*/
fmt.Printf("=======%#v \n", p)
}
2)
output
----------
$go run print_struct.go
==== {Sam 20}
====={Sam 20}
======{name:Sam age:20}
=======main.Person{name:"Sam", age:20}
Good article,download plugin premium in here,klik
ReplyDelete