Last active
August 16, 2017 21:43
-
-
Save bennofs/0b9f4373947c3045b8f57d648297605d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In Go, _variables_ are explicitly declared and used by | |
// the compiler to e.g. check type-correctness of function | |
// calls. | |
package main | |
import "fmt" | |
func main() { | |
// `var` declares 1 or more variables. | |
var a string = "initial" | |
fmt.Println(a) | |
// You can declare multiple variables at once. | |
var b, c int = 1, 2 | |
fmt.Println(b, c) | |
// Go will infer the type of initialized variables. | |
var d = true | |
fmt.Println(d) | |
// Variables declared without a corresponding | |
// initialization are _zero-valued_. For example, the | |
// zero value for an `int` is `0`. | |
var e int | |
fmt.Println(e) | |
// The `:=` syntax is shorthand for declaring and | |
// initializing a variable, e.g. for | |
// `var f string = "short"` in this case. | |
f := "short" | |
fmt.Println(f) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment