Go言語ポインタ

package main

import "fmt"

type student struct {
    name string
    subject string
    score int
}

func addScore(pStudent *student) {
    pStudent.score++
}

func main() {
    taro := student{
        name: "Taro",
        subject: "Math",
        score: 40,
    }
    addScore(&taro)

    fmt.Println(taro.score)
}

投稿者: chosuke

趣味はゲームやアニメや漫画などです

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です