Skip to content

Instantly share code, notes, and snippets.

@reetasingh
Created January 23, 2023 02:10
Show Gist options
  • Save reetasingh/72de55801a4e4db1911a4617868ee7e2 to your computer and use it in GitHub Desktop.
Save reetasingh/72de55801a4e4db1911a4617868ee7e2 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math"
)
type Circle struct {
r float64
}
func (c *Circle) area() float64 {
if c == nil {
// initalize nil receiver
c = new(Circle)
c.r = 10
}
return math.Pi * c.r * c.r
}
func main()
{
var c *Circle
fmt.Println(c.area()) // returns area
// will throw panic for c.r
fmt.Println(c.r)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment