package main
import"fmt"//定义一个结构体type Book struct{
title string
auth string}funcmain(){var book1 Book
book1.title ="Golang"
book1.auth ="zhang3"
fmt.Println("%v\n",book1)}
结构体传参
package main
import"fmt"//定义一个结构体type Book struct{
title string
auth string}funcchangeBook(book Book){//传递一个book的副本
book.auth ="666"}funcchangeBook3(book *Book){//指针传递
book.auth ="777"}funcmain(){var book1 Book
book1.title ="Golang"
book1.auth ="zhang3"
fmt.Println("%v\n",book1)//副本传递是不会改变结构体的值changeBook(book1)
fmt.Println("副本传递",book1)//指针传递changeBook3(&book1)
fmt.Println("指针传递",book1)}