Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

18
7

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 5 years have passed since last update.

型ごとのゼロ値まとめ

Posted at

こんにちは、@Solphaです。

これまでGoでプログラミングをする際、以下のように変数宣言時に型を指定していましたが、このあと変数に値を入力(初期化)しなかったらどう扱われるのかをまとめてみました。

<sample>
var suuzi int --> int型
var mozi string --> string型

#ゼロ値まとめ表

ゼロ値
boonlean false
int 0
float 0.0
string ""(空文字)
pointer nil(他言語でいうnullなど)
function nil(他言語でいうnullなど)
interface nil(他言語でいうnullなど)
slice nil(他言語でいうnullなど)
channel nil(他言語でいうnullなど)
map nil(他言語でいうnullなど)

#所感

  • 詳しくは本家golang.orgに書かれています
  • まとめてはみたものの、今の知識でゼロ値を活用するシーンが全く浮かびません(´∀`;A
18
7
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

Qiita Advent Calendar is held!

Qiita Advent Calendar is an article posting event where you post articles by filling a calendar 🎅

Some calendars come with gifts and some gifts are drawn from all calendars 👀

Please tie the article to your calendar and let's enjoy Christmas together!

18
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?