I'd like to explore the feats of pointer with the following codes:
#include <stdio.h>
int x = 3;
int main(void)
{
printf("x's value is %d, x's address is %p", x, &x);
//printf("x's address is stored in", &&x);
}
It works properly and get outputs
$ ./a.out
x's value is 3, x's address is 0x10b1a6018
When I utilize &x
, a memory space is set aside for it to keep the address 0x10b1a6018, so an address is printed.
Sequently, I intent to get info about the address which store another address.
#include <stdio.h>
int x = 3;
int main(void)
{
printf("x's value is %d, x's address is %p", x, &x);
printf("x's address is stored in", &&x);
}
But it report error as:
$ cc first_c_program.c
first_c_program.c:14:40: warning: data argument not used by format string [-Wformat-extra-args]
printf("x's address is stored in", &&x);
~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
first_c_program.c:14:42: error: use of undeclared label 'x'
printf("x's address is stored in", &&x);
^
1 warning and 1 error generated.
How could I retrieve information about the memory address which store the address of value x.