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)
    }
    

      

  • 相关阅读:
    docker 安装 redis
    docker 安装 fastdfs
    docker 安装 mysql5.7
    docker 安装 nacos
    docker 安装 gitlab-ce
    gitlab记录
    git记录
    ubuntu命令
    java html table 转 excel,给予jdom 和 poi
    自律挑战
  • 原文地址:https://www.cnblogs.com/chenadong/p/9051433.html
Copyright © 2011-2022 走看看