package main
import (
"fmt"
)
func main() {
// a := test
// a(22)
// // test(2)
// fmt.Printf("a的类型是: %T\n", a)
var res = strfunc("第一", "第二")
fmt.Printf("res: %T\n", res)
// testfunc(1, 2, test)
ab := testfunc
fmt.Printf("ab的类型是: %T\n", ab)
//定义类型
type Myint int
var abs Myint = 33
fmt.Printf("abs: %v\n", abs)
var abs2 int = 22
fmt.Printf("abs2: %T\n", abs2)
//强制转化
var adbs3 = int(abs)
fmt.Printf("adbs3的值: %v\n", adbs3)
var a, b = subab(1, 2)
fmt.Printf("a--b: %v\n%v\n", a, b)
}
func test(num int) {
fmt.Printf("\"传入的参数\": %v\n", num)
fmt.Printf("num的类型是: %T\n", num)
fmt.Printf("test的类型是: %T\n", test)
}
func addstr(a string, b string) string {
var res string
res = a + b
fmt.Printf("res: %v\n", res)
return res
}
func testfunc(num1 int, num2 int, testfunc func(int)) {
var sums int = 0
sums += num1
sums += num2
fmt.Printf("sums的值是: %v\n", sums)
}
func strfunc(s string, b string) string {
return s + b
}
func subab(a int, b int) (sum int, sub int) {
sum = a + b
sub = a - b
return sum, sub
}
go基本语法
最新推荐文章于 2024-09-24 14:34:45 发布