November 2013
Beginner
325 pages
9h 47m
English
Given that everything lives in memory and that you now know how to find the address where data starts, the next question is “How many bytes does this data type consume?”
Using sizeof() you can find the size of a data type. For example,
int main(int argc, const char * argv[])
{
int i = 17;
int *addressOfI = &i;
printf("i stores its value at %p\n", addressOfI);
*addressOfI = 89;
printf("Now i is %d\n", i);
printf("An int is %zu bytes\n", sizeof(int));
printf("A pointer is %zu bytes\n", sizeof(int *));
return 0;
}
Here there is yet another new token in the calls to printf(): %zu. The sizeof() function returns a value of type size_t, for which %zu is the correct placeholder token.
Build and run the program. If your ...
Read now
Unlock full access