Skip to content

Instantly share code, notes, and snippets.

@ZachOrr
Created August 19, 2013 00:13
Show Gist options
  • Save ZachOrr/6264796 to your computer and use it in GitHub Desktop.
Save ZachOrr/6264796 to your computer and use it in GitHub Desktop.
package main
import "fmt"
type Rectangle struct {
length, width int
}
func (r Rectangle) Area_by_value() int {
return r.length * r.width
}
func (r *Rectangle) Area_by_reference() int {
return r.length * r.width
}
func main() {
r1 := Rectangle{4, 3}
fmt.Println("Rectangle is: ", r1)
fmt.Println("Rectangle area is: ", r1.Area_by_value())
fmt.Println("Rectangle area is: ", r1.Area_by_reference())
fmt.Println("Rectangle area is: ", (&r1).Area_by_value())
fmt.Println("Rectangle area is: ", (&r1).Area_by_reference())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment