Created
August 19, 2013 00:13
-
-
Save ZachOrr/6264796 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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