Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
If you have an address, you can get the data stored there using the * operator. Have the log display the value of the integer stored at addressofI.
int main(int argc, const char * argv[])
{
int i = 17;
int *addressOfI = &i;
printf("i stores its value at %p\n", addressOfI);
printf("this function starts at %p\n", main);
printf("the int stored at addressOfI is %d\n", *addressOfI);
return 0;
}
Notice that the asterisk is used two different ways The first is in the declaration where you declare the variable addressOfI to be an int *. That is, it is a pointer to a place where an int can be stored.
The second is where you read the int value that is stored at the address stored in addressOfI. (Pointers are also called references. Thus, using the pointer to read data at the address is sometimes called dereferencing the pointer.)