On Sun, Mar 10, 2019 at 7:41 AM 박민우 <minwoo33p...@gmail.com> wrote: > > I am new to Go and I have read Go;s-declaration-syntax documentation. > > It states that: > > p: pointer to int > > Would be written as: > p *int > > However, other than declaration syntax, "&" is the symbol for "the pointer > to" like, > q := &int > The above code would be the same as: > var q *int > q = new(int) > So, I would suggest, > var q &int > to be more consistent, but Go's syntax wouldn't permit this. > > Is there a reason behind this decision? > I will get used to the syntax after a while, but in need of some reasonable > explanation.
The reason boils down to: this is how it is done in C. A pointer type is written as *int. A pointer variable q is dereferenced as *q. That is also what C looks like. Note that in Go there is no particular correspondence between the way that a type is written and the way that a value of that type is created. A map or chan type is created using the builtin function make, or using a composite literal. An int type is created by declaration, or implicitly. A slice type can be created by using a slice expression on an array value. The consistency you suggest just doesn't exist for Go. Ian -- 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 golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.