Anonymous user
Copy a string: Difference between revisions
→{{header|Go}}
No edit summary |
|||
Line 893:
Its internal reference is likely to point to the same underlying array as src,
but the language does not specify this behavior or make any guarantees about it.
::<lang go>package main
import "fmt"
func main() {
var creature string = "shark"
// point to creature
var pointer *string = &creature
// creature string
fmt.Println("creature =", creature) // creature = shark
// creature location in memory
fmt.Println("pointer =", pointer) // pointer = 0xc000010210
// creature through the pointer
fmt.Println("*pointer =", *pointer) // *pointer = shark
// set creature through the pointer
*pointer = "jellyfish"
// creature through the pointer
fmt.Println("*pointer =", *pointer) // *pointer = jellyfish
// creature string
fmt.Println("creature =", creature) // creature = jellyfish
}</lang>
=={{header|Groovy}}==
|