November 2013
Beginner
325 pages
9h 47m
English
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 in this example:
When you declared addressOfI to be an int *. That is, you told the compiler “It will hold an address where an int can be stored.”
When you read the int value that is stored at the address stored in addressOfI. (Pointers are also called references. ...
Read now
Unlock full access