-
Notifications
You must be signed in to change notification settings - Fork 0
/
my.go
45 lines (38 loc) · 723 Bytes
/
my.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
package main
import (
"fmt"
)
var arraySize = 10
type MyStruct struct {
Roll int
Name string
Marks float32
}
func main() {
array := myFunction1()
fmt.Println(array)
arrayOfPointers := myFunction2()
fmt.Println(arrayOfPointers)
}
func myFunction1() []*MyStruct {
array := make([]*MyStruct, arraySize)
for i := 0; i < arraySize; i++ {
array[i] = &MyStruct{
Roll: i + 1,
Name: fmt.Sprintf("Student %d", i+1),
Marks: float32(i) * 10,
}
}
return array
}
func myFunction2() *[]MyStruct {
array := make([]MyStruct, arraySize)
for i := 0; i < arraySize; i++ {
array[i] = MyStruct{
Roll: i + 1,
Name: fmt.Sprintf("Student %d", i+1),
Marks: float32(i) * 10,
}
}
return &array
}