<p>I am the most confused.</p>
<p>I pass a pointer of an int to a function. I dereference it into another variable, increment variable and assign the address of that variable to the original pointer.</p>
<p>But the change is lost.</p>
<p><a href="https://play.golang.org/p/b5cAMv1hIG" rel="nofollow">https://play.golang.org/p/b5cAMv1hIG</a></p>
<p>I have the dumb today and I don't see where this is failing</p>
<p>*EDIT: I didn't understand pointers, I get it now. Thanks to <a href="/u/chrj" rel="nofollow">/u/chrj</a> </p>
<hr/>**评论:**<br/><br/>janderssen: <pre><p>Also, you could simply do the following :</p>
<pre><code>func alter(a *int) {
*a++
}
</code></pre>
<p>Basically deferences the pointer to its value and increments it.</p></pre>chrj: <pre><p>Change the last line to:</p>
<pre><code>*a = b
</code></pre>
<p>You want to change what <code>a</code> is pointing to.</p></pre>Smokey_Circles: <pre><p>Oh...</p>
<p>I don't know why I thought I could change the address of the pointer. Evidently I hadn't internalised what was going on under the scenes of things like <code>json.Unmarshal</code> and it felt like I was re-assigning the address.</p>
<p>Thanks though, this clears up a lot of uncertainties I had :) </p></pre>
![](https://static.golangjob.cn/static/img/banner.png)