forked from ardanlabs/gotraining
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example1.go
55 lines (43 loc) · 1.28 KB
/
example1.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
45
46
47
48
49
50
51
52
53
54
55
// All material is licensed under the Apache License Version 2.0, January 2004
// http://www.apache.org/licenses/LICENSE-2.0
// http://play.golang.org/p/m4PJ0FpSwX
// The playground is actually a 64-bit env with 32-bit pointers
// The os/arch combo is named nacl/amd64p32
// Sample program to show how to declare variables.
package main
import "fmt"
// main is the entry point for the application.
func main() {
// Declare variables that are set to their zero value.
var a int
var b string
var c float64
var d bool
fmt.Printf("var a int \t %T [%v]\n", a, a)
fmt.Printf("var b string \t %T [%v]\n", b, b)
fmt.Printf("var c float64 \t %T [%v]\n", c, c)
fmt.Printf("var d bool \t %T [%v]\n\n", d, d)
// Declare variables and initialize.
// Using the short variable declaration operator.
aa := 10
bb := "hello"
cc := 3.14159
dd := true
fmt.Printf("aa := 10 \t %T [%v]\n", aa, aa)
fmt.Printf("bb := \"hello\" \t %T [%v]\n", bb, bb)
fmt.Printf("cc := 3.14159 \t %T [%v]\n", cc, cc)
fmt.Printf("dd := true \t %T [%v]\n\n", dd, dd)
// Specify type and perform a conversion.
aaa := int32(10)
fmt.Printf("aaa := int32(10) %T [%v]\n", aaa, aaa)
}
/*
Zero Values:
Type Initialized Value
Boolean false
Integer 0
Floating Point 0
Complex 0i
String "" (empty string)
Pointer nil
*/