I came across that exercise today, I thought I'd share. I won't give the source link for now so that you're not tempted to look at the answers. I could share it later. Also try not to use a computer while doing this, that would be too easy :P
Take this piece of code:
#include <stdio.h>
int main() {
int x[5];
printf("%p\n", x);
printf("%p\n", x+1);
printf("%p\n", &x);
printf("%p\n", &x+1);
return 0;
}
Assume we're working on a 32-bit machine (where
sizeof (int)is equal to 4) and x is stored at address
0xffbfd7d8.
The question is simple: What will be the output of each call to printf?