再牛逼的梦想也抵不住傻逼似的坚持!   设为首页 - 加入收藏
您的当前位置:小鱼资料库 > 计算机 > 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 */

   fmt.Printf( "Book 1 title : %s
", Book1.title)

   fmt.Printf( "Book 1 author : %s
", Book1.author)

   fmt.Printf( "Book 1 subject : %s
", Book1.subject)

   fmt.Printf( "Book 1 book_id : %d
", Book1.book_id)



   /* print Book2 info */

   fmt.Printf( "Book 2 title : %s
", Book2.title)

   fmt.Printf( "Book 2 author : %s
", Book2.author)

   fmt.Printf( "Book 2 subject : %s
", Book2.subject)

   fmt.Printf( "Book 2 book_id : %d
", Book2.book_id)

}
标签:

小鱼资料库 www.xiaoyuzl.com

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

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

Top