Pointers and Functions

agolangf · · 647 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I have 2 questions, may be somewhat noob.</p> <ol> <li>When I need to pass pointer reference to a function(as arguments) and why?</li> <li>When I need to return pointer reference from a function and why?</li> </ol> <p>Thanks a lot</p> <hr/>**评论:**<br/><br/>Aeaex: <pre><p>Do you know what a pointer actually is? Might be better to start there. Have you done the Tour?</p></pre>CrappyFap69: <pre><p>Of course I know what pointer is. But I ask the question from ground up to understand everything better</p></pre>0xjnml: <pre><p>I think the question stems from the confusion some people have with pointer vs. reference. But the term &#39;pointer reference&#39; beats that by a long way IMO.</p></pre>CapableCounteroffer: <pre><blockquote> <p>When I need to pass pointer reference to a function(as arguments) and why?</p> </blockquote> <p>An example of why you would want to do this is if you want the function to change what the pointer references. For example, say you have a pointer to an int called i, and it points to the address of something holding the value 5. Then in your function you take its single int argument and add 5 to it. You call the function on i as a value, then you check i. What do you get? i==5. You call the function on i passed as a pointer reference, then you check i. What do you get? i==10 as probably intended.</p></pre>CrappyFap69: <pre><p>That&#39;s great. Any other reason? And what about the second question?</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,免费领全套学习资料或添加微信:muxilin131420 备注:入群;或加QQ群:729884609

647 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传