doc: update golang.md (#282)

This commit is contained in:
jaywcjlove 2023-02-02 11:59:26 +08:00
parent 6614543e04
commit 358d8f4e17

View File

@ -185,6 +185,7 @@ fmt.Println("2d: ", twoDimension)
### 指针(Pointers)
<!--rehype:wrap-class=col-span-2-->
```go
func main () {
b := *getPointer()
@ -199,7 +200,11 @@ func getPointer () (myPointer *int) {
//不能直接进行操作,包括读写
var p *int
*p = 123 // panic nil pointer
```
---
```go
//而用new返回的是有默认值的指针, 为数据类型的默认值
func main(){
//有一块内存存放了10它的地址由系统自动分配别名是a
@ -243,15 +248,17 @@ const s string = "constant"
const Phi = 1.618
const n = 500000000
const d = 3e20 / n
```
常量声明可以使用 iota常量生成器 初始化,它用于
生成一组以相似规则初始化的常量,但是不用每行都
写一遍初始化表达式。
注意:
1.在一个const声明语句中在第一个声明的常量
所在的行iota被置为0然后在每一个有常量声明的行加一。
2.写在同一行的值是相同的
1. 在一个const声明语句中在第一个声明的常量所在的行iota被置为0然后在每一个有常量声明的行加一。
2. 写在同一行的值是相同的
```go
const (
a = iota
b