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="allyouhave" data-source="post: 1042601" data-attributes="member: 137791"><p>I'm just now teaching myself how to code in Objective-C (however, I have no background in C or any other extension), and I'm having some trouble understanding pointers. While reading around, I noticed a lot of people explaining that <u>all</u> objects are just pointers referencing objects. If this is true, then why do I ever have to explicitly create pointers? What is the difference between the follow two statements?</p><p></p><p>int numberOne = 12;</p><p>int *numberTwo = 14;</p><p></p><p>From what I remember from Java, it would follow that I could do numberOne = numberTwo, and therefore both are equal to 14. I can, however, still change either number individually. i.e. numberTwo = 17 (and therefor numberOne = 14 and numberTwo = 17). Of course, if I were to do the opposite, then the pointer numberTwo would point to the same object as numberOne, and every time I changed one of them, "both" would change.</p><p></p><p>But if all variables are actually just pointers, then aren't these two phrases exactly the same?</p><p></p><p>numberOne = numberTwo;</p><p><em>or</em></p><p>numberTwo = numberOne;</p><p></p><p>I have about five ebooks on Cocoa or Objective-C, and I'm only three chapters into my first book, so if any of you can reference a book or website for me to check out, or just shed some light on my problem with understanding, that would be faaantastic.</p></blockquote><p></p>
[QUOTE="allyouhave, post: 1042601, member: 137791"] I'm just now teaching myself how to code in Objective-C (however, I have no background in C or any other extension), and I'm having some trouble understanding pointers. While reading around, I noticed a lot of people explaining that [U]all[/U] objects are just pointers referencing objects. If this is true, then why do I ever have to explicitly create pointers? What is the difference between the follow two statements? int numberOne = 12; int *numberTwo = 14; From what I remember from Java, it would follow that I could do numberOne = numberTwo, and therefore both are equal to 14. I can, however, still change either number individually. i.e. numberTwo = 17 (and therefor numberOne = 14 and numberTwo = 17). Of course, if I were to do the opposite, then the pointer numberTwo would point to the same object as numberOne, and every time I changed one of them, "both" would change. But if all variables are actually just pointers, then aren't these two phrases exactly the same? numberOne = numberTwo; [i]or[/i] numberTwo = numberOne; I have about five ebooks on Cocoa or Objective-C, and I'm only three chapters into my first book, so if any of you can reference a book or website for me to check out, or just shed some light on my problem with understanding, that would be faaantastic. [/QUOTE]
Verification
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Pointers in Objective-C
Top