Skip to content

Commit

Permalink
Use %p to print &wallet.Balance in pointers-and-errors.md (quii#616)
Browse files Browse the repository at this point in the history
After the Stringer interface is implemented `%v` will no longer print the memory address but instead will invoke the Stringer interface which is confusing. 

Using `%p` means it will consistently print the variable's memory address.
  • Loading branch information
1Mark authored Oct 25, 2023
1 parent 94ddd31 commit 5a46062
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pointers-and-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func TestWallet(t *testing.T) {

got := wallet.Balance()

fmt.Printf("address of balance in test is %v \n", &wallet.balance)
fmt.Printf("address of balance in test is %p \n", &wallet.balance)

want := 10

Expand All @@ -133,7 +133,7 @@ func TestWallet(t *testing.T) {

```go
func (w Wallet) Deposit(amount int) {
fmt.Printf("address of balance in Deposit is %v \n", &w.balance)
fmt.Printf("address of balance in Deposit is %p \n", &w.balance)
w.balance += amount
}
```
Expand Down

0 comments on commit 5a46062

Please sign in to comment.