Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Pointers in Objective-C
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="systix" data-source="post: 1047277" data-attributes="member: 77241"><p>I don't know objective-c, i aim to learn though. In C however a good example of the use of pointers is a function that swaps two values. eg</p><p></p><p>[code]</p><p></p><p>voide main()</p><p>{</p><p> int val1, val2;</p><p> swap (val1, val2);</p><p>}</p><p></p><p>int swap (int val1, int val2)</p><p>{</p><p> int temp = val1;</p><p> val2 = val1;</p><p> val1 = temp;</p><p>}</p><p>[/code]</p><p></p><p></p><p></p><p>This will not work. The values are copied into the swap() function and swapped within the scope of the function, but not externaly to it. However, if we pass in pointers to the original variables we can indirectly access them and the swap will occure on the original values.</p><p></p><p>I hope this helps!</p></blockquote><p></p>
[QUOTE="systix, post: 1047277, member: 77241"] I don't know objective-c, i aim to learn though. In C however a good example of the use of pointers is a function that swaps two values. eg [code] voide main() { int val1, val2; swap (val1, val2); } int swap (int val1, int val2) { int temp = val1; val2 = val1; val1 = temp; } [/code] This will not work. The values are copied into the swap() function and swapped within the scope of the function, but not externaly to it. However, if we pass in pointers to the original variables we can indirectly access them and the swap will occure on the original values. I hope this helps! [/QUOTE]
Verification
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Pointers in Objective-C
Top