You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
742 B
52 lines
742 B
package main
|
|
|
|
import "fmt"
|
|
|
|
func main() {
|
|
fmt.Printf("%x\n", 456)
|
|
var m *int
|
|
fmt.Printf("%s\n", m)
|
|
//a := 10
|
|
b := 10
|
|
m = &b
|
|
fmt.Printf("%d\n", *m)
|
|
|
|
str := []string{"foo", "gomain"}
|
|
for i,s := range str{
|
|
fmt.Println(i, s)
|
|
}
|
|
|
|
// array
|
|
arr := [5] int{1:9, 4:1}
|
|
fmt.Println(arr)
|
|
|
|
// arrayx2
|
|
var value [][]int
|
|
arr1 := []int{1, 2, 3}
|
|
arr2 := []int{4, 5, 6}
|
|
value = append(value, arr1)
|
|
value = append(value, arr2)
|
|
fmt.Println(value[0])
|
|
for i:=0; i<2; i++{
|
|
for j:=0; j<3; j++{
|
|
fmt.Print(value[i][j])
|
|
}
|
|
}
|
|
|
|
var ptr *int
|
|
|
|
fmt.Printf("\nptr 的值为 : %x\n", ptr )
|
|
|
|
f1, f2 := 10, 20
|
|
fmt.Println(f1, f2)
|
|
swap(&f1, &f2)
|
|
fmt.Println(f1, f2)
|
|
}
|
|
|
|
func swap(a, b *int){
|
|
temp := *a
|
|
fmt.Println(*a)
|
|
*a = *b
|
|
*b = temp
|
|
}
|