I am reading The Ksplice Pointer Challenge in the page below:
https://blogs.oracle.com/ksplice/entry/the_ksplice_pointer_challenge
Could anyone read the article and tell me what is the value of x in that article?
The writer says that x is stored at address 0x7fffdfbf7f00 and x + 1 has address 0x7fffdfbf7f04.
When we write x + 1 does it mean that
value of x + 1 or
address of x + 1?
In this case, x is an array name and its value is the address of the first element of the array.
Should the article say that the first element of the array is stored at 0x7fffdfbf7f00 not x is stored at address 0x7fffdfbf7f00?
1 2 3 4 5 6 7 8 9
|
#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 that the first element of the array is stored at address 0x7fffdfbf7f00.
In this case, x will be decayed to the pointer to the first element of the array.
Result: 0x7fffdfbf7f00
In this case, x also will be decayed to the pointer to the first element of the array. And x + 1 = 0x7fffdfbf7f04.
Result: 0x7fffdfbf7f04
&x is a pointer to entire array.
Result: 0x7fffdfbf7f00
Result: 0x7fffdfbf7f14
I am confused what is x by itself?
&x is a pointer to entire array and its type is int (*)[5].
x is an array name but what is it?
x + 1 = array name + 1 doesn't make sense to me.
I think in that case the array name is decayed to a pointer and that is what I thought as above.
The article says that x is stored at address 0x7fffdfbf7f00 and this means the array name is stored at that address.
However, if that is the case x+ 1 doesn't make sense.