0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Go言語】Go言語基本型

Posted at

Go言語でのメモです。

Goには整数型、浮動小数点型、論理型、文字列型など基本的なデータ型があります。

整数型

サイズ(bit) 符号 最小値 最大値
int8 8 あり -128 127
int16 16 あり -32768 32767
int32 32 あり -2147483648 2147483647
int64 64 あり -9223372036854775808 9223372036854775807
uint8(byte) 8 なし 0 255
uint16 16 なし 0 65535
uint32 32 なし 0 4294967295
uint64 64 なし 0 18446744073709551615
main.go
	var i8 int8 = -128
	var i64 int64 = 65535

実装依存の整数型

32bit実装 64bit 符号
int 32bit 64bit あり
uint 32bit 64bit なし
uintptr ? ? なし
main.go
	var i int = -128
	var ui uint = 300
    fmt.Println(i)
    fmt.Printf("%T\n", i)        // 型を調べる(%T)
    fmt.Println(ui)
    fmt.Printf("%T\n", ui)        // 型を調べる(%T)

結果
-128
int
300
uint

浮動小数点型

サイズ (ビット)
float32 32
float64 64
main.go
	var f32 float32 = -128.0
	var f64 float32 =  3141.519
    fmt.Println(f32)
    fmt.Printf("%T\n", f32)
    fmt.Println(f64)
    fmt.Printf("%T\n", f32)

結果
-128
float32
3141.519
float32

論理値型

main.go
	var t bool = true
	var f bool = false
    fmt.Println(t, f)
結果
true false

文字列型

main.go
	var s string = "Hello World"
    fmt.Println(s)
    fmt.Printf("%T\n", s)
結果
Hello World
string
0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?