On Thu, Jan 31, 2019 at 8:46 PM 伊藤和也 <[email protected]> wrote:

> So in Go,
> The meaning of "declare" is allocate memory for a variable and initialize
> the variable explicitly or implicitly.
> e.g.
> var a int = 3   // "a" is explicitly initialized
> var b int         // "b" is implicitly initialized
>

You should spend some time reading the language specification. In this case
https://golang.org/ref/spec#Variable_declarations and other relevant
documents such as https://gobyexample.com/variables. Variable `b` in your
example is initialized to the appropriate "zero" value for its type. This
is behavior is meant to address one of the major flaws of C/C++ where
function (i.e., stack) local vars which are not explicitly initialized have
a random initial value based on the content of the stack at that juncture.

-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to