計算機科学のブログ

building storage - Structs - defined types

Head First GoJay McGavren(著)、O’Reilly Media)の Chapter 8(building storage - Structs)、p.241(COde Magnets)の解答を求めてみる。

コード

main.go

package main

import "fmt"

type student struct {
	name  string
	grade float64
}

func printInfo(s student) {
	fmt.Println("Name", s.name)
	fmt.Printf("Grade: %0.1f\n", s.grade)
}
func main() {
	var s student
	s.name = "Alonzo Cole"
	s.grade = 92.3
	printInfo(s)
}

入出力結果(Terminal, Zsh)

% go run ./main.go 
Name Alonzo Cole
Grade: 92.3
%