Add pointer and password app
This commit is contained in:
3
go-demo-4/go.mod
Normal file
3
go-demo-4/go.mod
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module password
|
||||||
|
|
||||||
|
go 1.23.6
|
||||||
20
go-demo-4/main.go
Normal file
20
go-demo-4/main.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
a := [4]int{1, 2, 3, 4}
|
||||||
|
reverse(&a)
|
||||||
|
fmt.Println(a)
|
||||||
|
|
||||||
|
var n *int
|
||||||
|
fmt.Println(*n)
|
||||||
|
}
|
||||||
|
|
||||||
|
func reverse(arr *[4]int) {
|
||||||
|
for idx, val := range *arr {
|
||||||
|
(*arr)[len(arr)-1-idx] = val
|
||||||
|
}
|
||||||
|
}
|
||||||
15
go-demo-4/pointers/main.go
Normal file
15
go-demo-4/pointers/main.go
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package pointers
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
a := 5
|
||||||
|
pointerA := &a
|
||||||
|
double(&a)
|
||||||
|
fmt.Println(*pointerA) // Дереференс (разыменование) указателя
|
||||||
|
fmt.Println(a)
|
||||||
|
}
|
||||||
|
|
||||||
|
func double(num *int) {
|
||||||
|
*num = *num * 2
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user