go..? go..! 3탄

samdaso-o·2021년 8월 26일
0

Go

목록 보기
3/3
post-thumbnail

이제 int를 다뤄보겠다.
곱셉을 출력하는 간단한(..?) 코드다.

file_name : main.go

import "fmt"

func multiply(a int, b int) int {
return a * b
}

func main() {
fmt.Println(multiply(2, 2))
}

출력값 : 4
간단하게 코드를 풀어보자면 a와 b 변수에는 타입을 int 선언을 해주었고, multiply가 출력될때의 타입 int로 지정을 해주었다.(타입 지정은 필수다!)

여기서 코드를 좀 더 축약가능하다.
multiply(a int, b int)를 multiply(a, b int)로 축약이 가능하다.

profile
ㅎㅅㅎ

0개의 댓글