LoginSignup
2
2

More than 5 years have passed since last update.

Go by Example: Constants

Last updated at Posted at 2015-01-24

(この記事は Go by Example: Constants を翻訳したものです。)

Goはcharacter, string, booleanと数学的値の定数をサポートしている。

package main

import "fmt"

import "math"

// 定数は constで宣言される。
const s string = "constant"

func main() {
    fmt.Println(s)

    // 定数宣言はvarでの宣言のようにどこでも現れる事ができる。
    const n = 500000000

    // 定数宣言は任意精度演算を行うことができる。
    const d = 3e20 / n
    fmt.Println(d)

    // 数の定数は明示的なキャストなどがされるまでは型が決まっていない。
    fmt.Println(int64(d))

    // 変数の代入や、関数の呼び出しよのうなコンテキストを使うことによって方が与えられる。
    // math.Sin はfloat64を引数をして取る。
    fmt.Println(math.Sin(n))
}

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2