#Buffer and Pointers

9 messages · Page 1 of 1 (latest)

hazy cove
#

So, I have been studying a bit about buffers.
What I don't understand in the code below is why pointing to my buffer gives me a string, but pointing to a variable of string type gives me a memory address.

func main() {
    var nothin string
    var buf bytes.Buffer
    buf.WriteString("Alhamdulilah!")
    fmt.Println(&buf)
    fmt.Println(&nothin)
}
#

Buffer and Pointers

dapper gyro
#

*bytes.Buffer satisfies the fmt.Stringer interface by implementing func String() string, and fmt.Println checks whether arguments you pass it implement that interface, and if so, call it to get the string representation

hazy cove
#

ahh

#

thanks mate

hazy cove
#

thats lowkey my last doubt

#

plus idk how to read the docs yet, im trying to find this 😭