zoukankan      html  css  js  c++  java
  • go语言练习:结构体

    package main
    
    import "fmt"
    
    type book struct {
    	title  string
    	author string
    	page   int
    }
    
    func main() {
    	var book1 book
    	book1.author = "Adong"
    	book1.page = 100
    	book1.title = "Story of Adong"
    	fmt.Println(book1.author, book1.page, book1.title)
    }


    //输出结果:
    Adong 100 Story of Adong

      

    package main
    
    import "fmt"
    
    type book struct {
    	title  string
    	author string
    	page   int
    }
    
    func main() {
    	var book1 book
    	book1.author = "Adong"
    	book1.page = 100
    	book1.title = "Story of Adong"
    	print_book(book1)
    }
    
    func print_book(b book) {            //这里函数接收到的参数是结构体
    	fmt.Println(b.author, b.page, b.title)
    }
    

    结构体指针:

    package main
    
    import "fmt"
    
    type book struct {
    	title  string
    	author string
    	page   int
    }
    
    func main() {
    	var book1 book
    	book1.author = "Adong"
    	book1.page = 100
    	book1.title = "Story of Adong"
    	print_book(book1)
    	var ptr *book = &book1
    	fmt.Println("book=", ptr.title)
    }
    
    func print_book(b book) { //这里函数接收到的参数是结构体
    	fmt.Println(b.author, b.page, b.title)
    }
    

      

  • 相关阅读:
    017-新闻表分页增删改查
    016-页面生命周期
    015-用户登录注册
    014-Session服务器状态保持
    013-Cookie状态保持
    012-ViewState状态保持
    011-Server服务器对象属性
    010-判断是否回传IsPostBack属性
    Github使用教程
    获取中文时间
  • 原文地址:https://www.cnblogs.com/chenadong/p/9051433.html
Copyright © 2011-2022 走看看