Go语言channel
作者:互联网
package main
import "fmt"
func main() {
// var chan 变量名 数据类型
// 声明channel
var intChan chan int
intChan = make(chan int, 3)
fmt.Printf("intChan = %v intChan地址 = %v\n", intChan, &intChan)
// 写入数据
intChan <- 2
num := 6
intChan <- num
intChan <- 8
fmt.Printf("len = %v, cap = %v\n", len(intChan), cap(intChan))
var num2 int
// 读取数据
num2 = <- intChan
fmt.Println("num2 = ", num2)
fmt.Printf("len = %v, cap = %v\n", len(intChan), cap(intChan))
}
标签:语言,intChan,fmt,chan,var,int,Go,main,channel 来源: https://blog.csdn.net/qq2942713658/article/details/113454442