Created
June 25, 2018 13:16
-
-
Save ksakae1216/048e8f8b404408fcde32fe22334f7248 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 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