Demo entry 2530605

go struct

   

Submitted by Ishan Khare on Aug 27, 2015 at 12:51
Language: Go. Code size: 292 Bytes.

package main

import (
  "fmt"
  "math"
)

type Circle struct {
  x, y, r float64
}

func (c *Circle) area() float64 {               // a `receiver` between func and function name
  return math.Pi * c.r * c.r
}

func main() {
  c := Circle{0, 0, 5}
  fmt.Println(c.area())
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).