forked from iamshaunjp/golang-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvar,string,num.go
41 lines (28 loc) · 851 Bytes
/
var,string,num.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
package main
import "fmt"
func main() {
// string variables
var nameOne string = "mario"
var nameTwo = "luigi"
var nameThree string
fmt.Print(nameOne, nameTwo, nameThree)
nameOne = "peach"
nameThree = "bowser"
fmt.Print(nameOne, nameTwo, nameThree)
// the following is allowed inside functions only
nameFour := "yoshi"
fmt.Print(nameFour)
// int variables
var ageOne int = 20
var ageTwo = 30
ageThree := 40
fmt.Print(ageOne, ageTwo, ageThree)
// bits & memory
// var numOne int8 = 25
// var numTwo int8 = 128 // too large a number for 8-bit
// var numTwo uint = -25 unsigned ints cannot be negative
var scoreOne float32 = 25.98
var scoreTwo float64 = 1965385877.5
var scoreThree = 1.5 // inferred as float64
fmt.Print(scoreOne, scoreTwo, scoreThree)
// for more info see https://golang.org/ref/spec#Numeric_types