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

      

  • 相关阅读:
    CentOS7的内核优化
    centos7 系统优化脚本
    Centos7之系统优化
    Jenkins安装
    Zabbix安装
    Systemd 入门教程:命令篇
    开源ERP系统Odoo搭建文档
    SSH详解
    使用pm2来保证Spring Boot应用稳定运行
    npm安装与使用
  • 原文地址:https://www.cnblogs.com/chenadong/p/9051433.html
Copyright © 2020-2023  润新知