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. Appdelegate 导航操作

    隐藏返回按钮 self.navigationItem.hidesBackButton = YES; 设置导航的透明度 self.navigationController.navigationBar.t ...

  2. ASP.NET MVC 3 Razor Views in SharePoint

    http://tqcblog.com/2011/01/22/asp-net-mvc-3-razor-views-in-sharepoint/ ASP.NET MVC 3 has just been r ...

  3. iOS崩溃日志分析-b

    1名词解释 1.1. UUID 一个字符串,在iOS上每个可执行文件或库文件都包含至少一个UUID,目的是为了唯一识别这个文件. 1.2. dwarfdump 苹果提供的命令行工具,其中一些功能就是查 ...

  4. 搭建 Win CE6.0 设备开发环境

    1.操作系统最好基于Windows XP.Vista.Win7 或以上的版本对ActiveSync软件不支持  2.安装VS2008,以及SP1 (一定要装SP1) 3.安装ActiveSync 4. ...

  5. ExtJS4.2学习(16)制作表单(转)

    鸣谢:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-12-10/188.html --------------- ...

  6. pmtest1.asm pmtest2.asm pmtest5.asm 这几个比较重要.

    读代码时注意Label后面的文字:desc表示是描述符,seg表示是段 pmtest1.asm 主要讲进入保护模式 http://www.cnblogs.com/wanghj-dz/archive/2 ...

  7. Postman(API & HTTP请求调试插件)和Apizza fiddler

    http://blog.csdn.net/u011012932/article/details/51456263#comments

  8. 在C++中子类继承和调用父类的构造函数方法

    构造方法用来初始化类的对象,与父类的其它成员不同,它不能被子类继承(子类可以继承父类所有的成员变量和成员方法,但不继承父类的构造方法).因此,在创建子类对象时,为了初始化从父类继承来的数据成员,系统需 ...

  9. 【JavaScript 开发规范】

    Javascript 最佳实践http://sofish.de/1171http://sofish.de/1181 总是使用 ‘var’ √ 特性检测而非浏览器检测 √ 使用方括号记法 √ 使用&qu ...

  10. ☀【CSS3】box-sizing

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...