-
Notifications
You must be signed in to change notification settings - Fork 0
/
variable-practice01.go
44 lines (33 loc) · 1.05 KB
/
variable-practice01.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* Alta3 Research | RZFeeser
Variables */
// 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() {
// variables declared inside of main() are at the "function" level
// var name type = expression
var instructor string = "rzfeeser"
fmt.Println(instructor)
// `var` declares 1 or more variables
// here we let the compiler infer the type
var a = "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 = "apple"` in this case.
f := "apple"
fmt.Println(f)
}