以下代码在VC环境下运行:
#include
<
stdio.h
>
main( void )
{
int x;
int * p;
x = 10 ;
p =& x;
printf( " The address of x is %p \n "
" The value of p is %p \n\n " , & x, p);
printf( " The value of x is %p \n "
" The value of *p is %p \n\n " , x, * p);
printf( " Proving that * and & are complement of "
" each other \n&*p=%p\n*&p=%p \n\n " ,
&* p, *& p);
return 0 ;
}
main( void )
{
int x;
int * p;
x = 10 ;
p =& x;
printf( " The address of x is %p \n "
" The value of p is %p \n\n " , & x, p);
printf( " The value of x is %p \n "
" The value of *p is %p \n\n " , x, * p);
printf( " Proving that * and & are complement of "
" each other \n&*p=%p\n*&p=%p \n\n " ,
&* p, *& p);
return 0 ;
}
运行完语句p=&x;后:
Name Value
+ &x 0x0012ff7c
+ &p 0x0012ff78 "|"
Memory:
0012FF6D CC CC CC CC CC CC CC CC CC CC CC 烫烫烫烫烫.
0012FF78 7C FF 12 00 0A 00 00 00 C0 FF 12 |..........
0012FF83 00 39 11 40 00 01 00 00 00 70 0E .9.@.....p.
程序结果:
The address of x is 0012FF7C
The value of p is 0012FF7C
The value of x is 0000000A
The value of *p is 0000000A
Proving that * and & are complement ofeach other
&*p=0012FF7C
*&p=0012FF7C