Go by Example: Variables
来源:互联网 发布:蒂华纳vs普埃布拉数据 编辑:程序博客网 时间:2024/06/13 00:07
在Go语言中,所有的变量都是显示声明的。编译器会使用变量进行相应的操作,例如:在函数调用时进行类型检查。
package mainimport "fmt"func main() { //使用var声明单个或者多个变量 var a string = "initial" fmt.Println(a) //你也可以一次声明多个变量 var b, c int = 1, 2 fmt.Println(b, c) //Go语言会利用初始化的变量推断出变量的类型 var d = true fmt.Println(d) //变量声明时,如果没有进行初始化。那么它的值为相应类型的零值(<em>zero-valued</em>) //例如:int型变量的零值为0. var e int fmt.Println(e) //:=操作符同时完成了变量声明和赋值的操作 //这里相当与var f string = "short" f := "short" fmt.Println(f)}
输出
$ go run variables.goinitial1 2true0short
下一个例子:Constants。
英文原文
0 0
- Go by Example: Variables
- 3.Go by Example: Variables
- Go by Example: Values
- Go by Example: Constants
- Go by Example: For
- Go by Example: Switch
- Go by Example: Arrays
- Go by Example: Slices
- Go by Example: Maps
- Go by Example: Range
- Go by Example: Functions
- Go by Example: Closures
- Go by Example: Recursion
- Go by Example: Pointers
- Go by Example: JSON
- 2.Go by Example: Values
- 4.Go by Example: Constants
- 5.Go by Example: For
- mac下如何改变当前环境目录(程序实现)
- hibernate——两种查询方式
- QT编译./configure参数的详细解释
- Android 文件管理
- C++中实现委托(Delegate)
- Go by Example: Variables
- 已将博客迁移至博客园, 但关联的代码片还在这
- struts2拦截器的使用
- 【杂题】HDOJ 4768 Flyer
- 顶级c程序员之路 基础篇 - 第一章 关键字的深度理解 number-1
- 悲催的程序员,以及程序员的悲催
- HDU 5092 Seam Carving(DP)
- Android: 在WebView中获取网页源码
- QtWebkit嵌入flash的总结(mac平台)