I may be misunderstanding, but 

var name = &someOtherVariable


is fine but the point is & is a unary operator that means 'return the 
pointer to the variable to the right of this operator' and is not a type 
specification, whereas *typename is a type specification that tells the 
compiler and hints in some case implied dereferencing as is used with 
method receivers, when the * can be left out.

You can't & at a constant, it has no address, only variables have 
addresses. Addresses are required to create pointers.

& always goes with a variable

* can indicate a type is a pointer or that the value is a pointer referring 
to a variable

* indicates accessing the variable requires requesting the content at the 
given address, the value is a pointer, 

& returns a pointer to a value, which has an address (it can't be used 
without a variable, just to repeat).

On Sunday, 10 March 2019 17:18:17 UTC+1, 박민우 wrote:
>
> 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> 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.

Reply via email to