"Go 포인터"의 두 판 사이의 차이

 
45번째 줄: 45번째 줄:
* [[Go 자료형 포인터인지 확인]]
* [[Go 자료형 포인터인지 확인]]
* [[Go 구조체 전달 vs 포인터 전달]]
* [[Go 구조체 전달 vs 포인터 전달]]
* [[k8s.io/utils/ptr]]
}}
}}



2024년 5월 10일 (금) 13:58 기준 최신판

1 개요[ | ]

Go Pointers
package main
import "fmt"
func main() {
	i, j := 42, 2701

	p := &i         // point to i
	fmt.Println(*p) // read i through the pointer
	*p = 21         // set i through the pointer
	fmt.Println(i)  // see the new value of i

	p = &j         // point to j
	*p = *p / 37   // divide j through the pointer
	fmt.Println(j) // see the new value of j
}
package main
import "fmt"
func zeroval(ival int) {
    ival = 0
}
func zeroptr(iptr *int) {
    *iptr = 0
}
func main() {
    i := 1
    fmt.Println("initial:", i)
    zeroval(i)
    fmt.Println("zeroval:", i)
    zeroptr(&i)
    fmt.Println("zeroptr:", i)
    fmt.Println("pointer:", &i)
}

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}