mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 01:21:38 +08:00
04.4.1.md
This commit is contained in:
13
eBook/examples/chapter_4/string_pointer.go
Normal file
13
eBook/examples/chapter_4/string_pointer.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
s := "good bye"
|
||||
var p *string = &s
|
||||
*p = "ciao"
|
||||
|
||||
fmt.Printf("Here is the pointer p: %p\n", p) // prints address
|
||||
fmt.Printf("Here is the string *p: %s\n", *p) // prints string
|
||||
fmt.Printf("Here is the string s: %s\n", s) // prints same string
|
||||
}
|
Reference in New Issue
Block a user