"Go 문자열 포인터를 문자열로 변환"의 두 판 사이의 차이

(같은 사용자의 중간 판 5개는 보이지 않습니다)
1번째 줄: 1번째 줄:
==개요==
==개요==
;Go 문자열을 문자열 포인터로 변환
;Go 문자열 포인터를 문자열로 변환


<syntaxhighlight lang='go' run>
<syntaxhighlight lang='go' run>
9번째 줄: 9번째 줄:
func main() {
func main() {
temp := "Hello, 世界"
temp := "Hello, 世界"
var pointer *string
foo := &temp
pointer = &temp
bar := *foo
fmt.Println(pointer) // 0xc00010a210
fmt.Println(foo) // 0xc00010a210
fmt.Println(*pointer) // Hello, 世界
fmt.Println(bar) // Hello, 世界
}
}
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang='go' run>
<syntaxhighlight lang='go' run>
package main
package main
25번째 줄: 26번째 줄:


func main() {
func main() {
temp := "Hello, 世界"
foo := ptr.To("Hello, 世界")
var pointer *string = ptr.To[string](temp)
bar := *foo
fmt.Println(pointer) // 0xc00010a210
fmt.Println(foo) // 0xc00010a210
fmt.Println(*pointer) // Hello, 世界
fmt.Println(bar) // Hello, 世界
}
}
</syntaxhighlight>
</syntaxhighlight>

2024년 6월 13일 (목) 13:22 판

1 개요

Go 문자열 포인터를 문자열로 변환
package main

import "fmt"

func main() {
	temp := "Hello, 世界"
	foo := &temp
	bar := *foo
	fmt.Println(foo) // 0xc00010a210
	fmt.Println(bar) // Hello, 世界
}
package main

import (
	"fmt"

	"k8s.io/utils/ptr"
)

func main() {
	foo := ptr.To("Hello, 世界")
	bar := *foo
	fmt.Println(foo) // 0xc00010a210
	fmt.Println(bar) // Hello, 世界
}

2 같이 보기

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