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

 
(같은 사용자의 중간 판 4개는 보이지 않습니다)
39번째 줄: 39번째 줄:


==같이 보기==
==같이 보기==
{{z컬럼3|
* [[포인터]]
* [[포인터]]
* [[Go 포인터 리시버]]
* [[Go 포인터 리시버]]
* [[Go 포인터 슬라이스]]
* [[Go 자료형 포인터인지 확인]]
* [[Go 구조체 전달 vs 포인터 전달]]
* [[k8s.io/utils/ptr]]
}}


==참고==
==참고==
* https://tour.golang.org/moretypes/1
* https://tour.golang.org/moretypes/1


[[분류: Go]]
[[분류: Go 포인터]]

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 }}