go20/day01/scope/main.go
yumaojun03 0761778363 ```
docs(day01): 添加运算符和变量作用域文档

- 新增运算符文档,详细介绍Go语言的算术、关系、逻辑、位、赋值等运算符
- 添加变量作用域文档,涵盖局部变量、全局变量、作用域嵌套和可见性规则
- 补充相关代码示例和实践案例
- 更新README目录结构,添加新章节链接
```
2025-12-28 15:53:05 +08:00

32 lines
637 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import "fmt"
var (
// main 包里面的变量
age = 18
)
func main() {
var a = "parent"
fmt.Println("outer:", a) // parent
{
a = "child" // 子作用域声明了同名新变量(遮蔽外层 a
fmt.Println("inner:", a) // child
}
fmt.Println("outer again:", a) // 仍为 child
// 局部变量
var b = "parent"
fmt.Println("outer:", b) // parent
{
// var b = "child"
// 新的局部变量b
b := "child" // 子作用域声明了同名新变量(遮蔽外层 a
fmt.Println("inner:", b) // child
}
fmt.Println("outer again:", b) // 仍为 parent
fmt.Println(age)
}