go语言从例子开始之Example18.struct结构体
2024-09-06 01:17:14
Go 的结构体 是各个字段字段的类型的集合。这在组织数据时非常有用
Example:
package main import "fmt" type product struct{
name string
number int
} func main(){
//不指定字段。结构体赋值
fmt.Println(product{"phone", 10})
//注意字段名不加引号
fmt.Println(product{name:"abc", number: 30}) //省略字段默认为0
fmt.Println(product{name: "def"}) //使用点访问结构体属性。
s := product{name: "yhleng", number: 30}
fmt.Println(s.name, s.number) //&生成结构体指针,指针被自动解析引用
sptr := &s
fmt.Println(sptr.name) sptr.name = "xzdylyh"
fmt.Println(sptr.name)
}
Result:
$ go run example.go
{phone 10}
{abc 30}
{def 0}
yhleng 30
yhleng
xzdylyh
最新文章
- python 基础
- Ubuntu下Nutch1.2的使用
- 前端二:CSS
- Windows Store App 插值动画
- R语言-神经网络包RSNNS
- Hive[4] 数据定义 HiveQL
- FZU 2016 summer train I. Approximating a Constant Range 单调队列
- 恭贺自己itpub和csdn双双获得专家博客称号
- [LeetCode]题解(python):129-Sum Root to Leaf Numbers
- 什么是Hadoop
- 自定义Git之搭建Git服务器
- Tomcat之URL查找的过程
- top命令用法详解
- 【java源码】解读HashTable类背后的实现细节
- Activit工作流学习例子
- bootstrap collapse 无法收回
- emoji &; click copy
- Arrow functions and the ‘this’ keyword
- MFC-Dialog各函数的执行顺序
- [PHP] constant variable
热门文章
- 02.自定义banner、全局配置文件、@Value获取自定义配置、@ConfigurationProperties、profiles配置
- wait与sleep区别?
- GSL+DevC++使用
- 转载:Eclipse下的java工程目录
- ubuntu软件源变更阿里源和arm板子变更国内源
- flask01
- springMVC使用map接收入参 + mybatis使用map 传入查询参数
- 获取数组NSArray元素的className
- Bugku | Easy_Re
- JDK1.8 动态代理机制及源码解析