Skip to content

Instantly share code, notes, and snippets.

@ksakae1216
Created June 25, 2018 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ksakae1216/048e8f8b404408fcde32fe22334f7248 to your computer and use it in GitHub Desktop.
Save ksakae1216/048e8f8b404408fcde32fe22334f7248 to your computer and use it in GitHub Desktop.
package funcpkg
import "fmt"
// PointerFunc ポインタのサンプルです
func PointerFunc() {
intA := 10
intB := 10
calc(intA, &intB) // "&"を付ける
fmt.Println("値渡し -> ", intA)
fmt.Println("ポインタ -> ", intB)
}
// "calc"のように先頭が小文字だと他ファイルからは呼べない
func calc(intA int, intB *int) {
intA = intA + 1 // 値渡し
*intB = *intB + 1 // ポインタ(参照渡し)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment