Thank you for the explanation! and sorry for the typo, I meant to say something like, someInteger := 0 q := &someInteger or q := &SomeStructure{} as an example of & symbol as "pointer to".
Anyway, I would say C's declaration syntax int *p makes more sense because *p , "where p points to", is int. However, it also makes sense to use the same asterisk for pointer declaration. Thank you for mentioning creation of other types too, It really helped me get over it ! :) I believe I just need some getting used to ! 2019년 3월 10일 일요일 오후 11시 46분 13초 UTC+9, Ian Lance Taylor 님의 말: > > On Sun, Mar 10, 2019 at 7:41 AM 박민우 <minwoo...@gmail.com <javascript:>> > 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.