package main import "fmt" type Rectangle struct { width, height int } func rectangleScalaA(rect *Rectangle, factor int){ rect.width = rect.width * factor rect.height = rect.height * factor } func rectangleScalaB(rect Rectangle, factor int){ rect.width = rect.width * factor rect.height = rect.height * factor } func main() { rect1 := Rectangle{30, 30} rectangleScalaA(&rect1, 10) fmt.Println(rect1) //주소를 넘겨주기 때문에 바뀐 값이 들어감 rect2 := Rectangle{30, 30} rectangleScalaB(rect2, 10) fmt.Println(rect2) //값을 넘겨주기 때문에 rect2는 변하지 않음. } /* 포인터 변수는 pointerVar = &{} 형태 그래서 &pointerVar은 주소를 나타내고 *pointerVar는 주소의 값을 나타낸다. */
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more