golang快速入门-13-golang的结构体struct

与c/c++一样

 

//type 关键字可以定义类型的别名 
type myint int

//type 关键字可以定义一个结构体
type Book struct 
{
    title string
    auth  string
}

// 传值
func changeBook(book Book) 
{
    //传递一个book的副本
    book.auth = "666"
}

// 传地址
func changeBook2(book *Book) 
{
    //指针传递
    book.auth = "777"
}

 

posted @ 2021-03-18 00:11  从程序员到CTO  阅读(59)  评论(0)    收藏  举报
交流加我QQ:39667545