Why did my value receivers have the same address?

📰 Medium · Programming

Understand why value receivers in Go may have the same address due to optimization of empty structs, and how to verify this behavior with a simple code example.

intermediate Published 27 Apr 2026
Action Steps
  1. Write a Go program using an empty struct with a value receiver method
  2. Run the program and observe the printed addresses
  3. Modify the struct to include a field and re-run the program to compare the results
  4. Use the `fmt.Printf` function with `%p` to print the address of the receiver
  5. Verify that the address is the same for each method call when using an empty struct
Who Needs to Know This

Software engineers and developers working with Go can benefit from understanding this concept to avoid unexpected behavior in their code, especially when using value receivers with empty structs.

Key Insight

💡 Empty structs in Go occupy no memory, leading to the same address being printed for each method call when using value receivers.

Share This
Did you know that value receivers in Go can have the same address due to empty struct optimization?
Read full article → ← Back to Reads