A struct literal denotes a newly allocated struct value by listing the values of its fields.

You can list just a subset of fields by using the Name: syntax. (And the order of named fields is irrelevant.)

The special prefix & constructs a pointer to a newly allocated struct.

package main 

import "fmt"

type Vertex struct {
X, Y int
} var (
p = Vertex{, } // has type Vertex
q = &Vertex{, } // has type *Vertex
r = Vertex{X: } // Y:0 is implicit
s = Vertex{} // X:0 and Y:0
)
func main() {
fmt.Println(p, q, r, s)
}

A Tour of Go Struct Literals的更多相关文章

  1. A Tour of Go Map literals

    Map literals are like struct literals, but the keys are required. package main import "fmt" ...

  2. A Tour of Go Map literals continued

    If the top-level type is just a type name, you can omit it from the elements of the literal. package ...

  3. A Tour of Go Struct Fields

    Struct fields are accessed using a dot. package main import "fmt" type Vertex struct { X i ...

  4. go官网教程A Tour of Go

    http://tour.golang.org/#1 中文版:http://go-tour-cn.appsp0t.com/#4 package main import ( "fmt" ...

  5. Golang 学习资料

    资料 1.How to Write Go Code https://golang.org/doc/code.html 2.A Tour of Go https://tour.golang.org/li ...

  6. Go structs、slices、maps

    [Go structs.slices.maps] 1.定义时*在变量名后面,使用时*在变量名前面. 2.定义struct,type在前,struct关键字在后. 3.指针可以指定struct. 4.A ...

  7. Golang测试技术

    本篇文章内容来源于Golang核心开发组成员Andrew Gerrand在Google I/O 2014的一次主题分享“Testing Techniques”,即介绍使用Golang开发 时会使用到的 ...

  8. 10 The Go Programming Language Specification go语言规范 重点

    The Go Programming Language Specification go语言规范 Version of May 9, 2018 Introduction 介绍 Notation 符号 ...

  9. soj 1015 Jill's Tour Paths 解题报告

    题目描述: 1015. Jill's Tour Paths Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Every ...

随机推荐

  1. TOKEN+签名验证

    TOKEN+签名验证 首先问大家一个问题,你在写开放的API接口时是如何保证数据的安全性的?先来看看有哪些安全性问题在开放的api接口中,我们通过http Post或者Get方式请求服务器的时候,会面 ...

  2. DB天气app冲刺第七天

    今天估计得分应该是最差的了. 今天因为完全没准备所以在界面UI上面根本就是相当于没弄.结果今天的各组报告里自己做得很不好.不过好在只是项目的中间期,不碍大事. 今天也完成了任务.可以说超额了也.因为吃 ...

  3. 触发UIButton长按事件

    UIButton *aBtn=[UIButton buttonWithType:UIButtonTypeCustom]; [aBtn setFrame:CGRectMake(40, 100, 60,  ...

  4. 使用WiX Toolset创建.NET程序发布Bootstrapper(安装策略管理)(一)-----初识WiX (转)

    原文地址:http://blog.csdn.net/rryqsh/article/details/8274832 Visual Studio 打包安装七宗罪 开发.NET的人,肯定会使用Visual ...

  5. 深入研究java.lang.ProcessBuilder类

     深入研究java.lang.ProcessBuilder类 一.概述       ProcessBuilder类是J2SE 1.5在java.lang中新添加的一个新类,此类用于创建操作系统进程,它 ...

  6. VS2012格式化插件配置备份

    VS2012联机插件AStyle --style=allman --indent=spaces=4 --align-pointer=type --align-reference=type --max- ...

  7. 防止横竖屏时,iphone自动缩放的一段js代码

    function orientation_change() {     var viewport = document.querySelector('meta[name="viewport& ...

  8. w3c subscribe

    http://www.w3.org/html/ig/zh/ http://blog.csdn.net/spring21st/article/details/6126537 http://www.w3c ...

  9. Bash Promot

    http://www.askapache.com/linux/bash-power-prompt.html 强大的Bash Promt命令 http://bbs.51cto.com/thread-11 ...

  10. UINavigationController使用的注意事项

    1.常用属性viewControllers //所有在栈中的控制器topViewController //栈顶控制器navigationBar //导航栏 竖屏下默认44,横屏默认32 2.对navi ...