-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello.go
65 lines (49 loc) · 1.26 KB
/
hello.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
56
57
58
59
60
61
62
63
64
65
package main
import "fmt"
func changeByValue(y string) {
y = "This was passed by value"
}
func changeByRef(y *string) {
*y = "This was passed by reference"
}
// multiple return
func multipleReturnFunction(x string) (string, int) {
return "It was good", len(x)
}
//naked return
func nakedReturnFunction(sum int) (x, y int) {
x = sum * 4 / 9
y = sum - x
return
}
func main() {
//declaring a variable and assigning it later
var a string
a = "Aanisha"
//declaring a variable as well as assigning it simultaneously
b := 6
//printing a line by concatenating strings and integers
fmt.Println("Hello World!", a, b)
//declaring a constant and printing it
const y = "y is constant"
fmt.Println(y)
xx, yy := nakedReturnFunction(45)
fmt.Println("Naked return function executed: ", xx, yy)
//Introduction to pointers
s := "Lets check what pointer is"
changeByValue(s)
fmt.Println("Changed by value: ", s)
changeByRef(&s)
fmt.Println("Changed by reference: ", s)
//Pointer declaration
x := new(string)
changeByRef(x)
fmt.Println(*x)
fmt.Println(len(*x))
var boolean bool
fmt.Printf("The type of variable boolean is %T\n", boolean)
//multiple return from functions
str := "How was your day?"
sx, sy := multipleReturnFunction(str)
fmt.Println(sx, sy)
}