Storing addresses in pointers

What if you wanted to store an address in a variable? You could stuff it into an unsigned integer that was the right size, but the compiler will help you catch your mistakes if you are more specific when you give that variable its type. For example, if you wanted a variable named ptr that holds the address where a float can be found, you would declare it like this:

 ​ ​ ​ ​f​l​o​a​t​ ​*​p​t​r​;​

We say that ptr is a variable that is a pointer to a float. It does not store the value of a float; it can hold an address where a float may be stored.

Declare a new variable named addressOfI that is a pointer to an int. Assign it the address of i.

i​n​t​ ​m​a​i​n​(​i​n​t​ ​a​r​g​c​,​ ​c​o​n​s​t​ ​c​h​a​r​ ​*​ ...

Get Objective-C Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.