how statements affect each other causing different print?

Viewed 21
type Person struct{} //a null struct
func main(){
  p1 := new(Person)
  p2 := new(Person)
  fmt.Println(p1==p2)
}
// console gives: 
false
type Person struct{} //a null struct
func main(){
  p1 := new(Person)
  p2 := new(Person)
  fmt.Println(p1==p2)
  fmt.Println(p1,p2) //added new line
}
// console gives: 
true
&{} &{}

you can see the funny thing about the code, how the latter line affect the output of the former line? I can't figure out the reason...

0 Answers
Related