-
Notifications
You must be signed in to change notification settings - Fork 0
/
variables.go
44 lines (33 loc) · 822 Bytes
/
variables.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
44
package main
import (
"fmt"
"os"
"reflect"
)
var (
name = os.Getenv("USER") // inferred type reflect.TypeOf(name) will be string
module = 4.3
)
const dob = "01/01/1990"
func main() {
// short assignment
foo := "bar"
bar := &foo // pointer using & | reference with *
course := "Go Fundamentals"
fmt.Println("Name is", name)
fmt.Println("Module is of type", reflect.TypeOf(module))
fmt.Println("The address of foo is", bar, "and the value of foo is", *bar)
fmt.Println("Current course is", course)
changeCourse(&course) // pass address in memory
fmt.Println("Course is now changed to", course)
// printAllEnvs()
}
func changeCourse(course *string) string {
*course = "Web applications with Go"
return *course
}
func printAllEnvs() {
for _, env := range os.Environ() {
fmt.Println(env)
}
}