再牛逼的梦想也抵不住傻逼似的坚持!   设为首页 - 加入收藏
您的当前位置:小鱼资料库 > 计算机 > go教程 > 正文

Go结构作为函数参数-Go实例教程|

来源:网络 编辑:听音 时间:2022-06-18

Go 结构作为函数参数

package main



import "fmt"



type Books struct {

   title string

   author string

   subject string

   book_id int

}

func main() {

   var Book1 Books    /* Declare Book1 of type Book */

   var Book2 Books    /* Declare Book2 of type Book */



   /* book 1 specification */

   Book1.title = "Go Programming"

   Book1.author = "Mahesh Kumar"

   Book1.subject = "Go Programming Tutorial"

   Book1.book_id = 6495407



   /* book 2 specification */

   Book2.title = "Telecom Billing"

   Book2.author = "Zara Ali"

   Book2.subject = "Telecom Billing Tutorial"

   Book2.book_id = 6495700



   /* print Book1 info */

   printBook(Book1)



   /* print Book2 info */

   printBook(Book2)

}

func printBook( book Books ) {

   fmt.Printf( "Book title : %s
", book.title);

   fmt.Printf( "Book author : %s
", book.author);

   fmt.Printf( "Book subject : %s
", book.subject);

   fmt.Printf( "Book book_id : %d
", book.book_id);

}
标签:

小鱼资料库 www.xiaoyuzl.com

Copyright © 2020-2022 XIAOYUZL. All rights reserved. 冀ICP备2020029262号-2

声明:本站分享的文章、资源等均由网友上传,版权归原作者所有,只用于搜集整理。如有侵权,请您与站长联系,我们将及时处理!

Top