C语言精彩编程百例第9个例子 指针操作符
源程序如下:
#include <stdio.h>
void main ()
{
int *p;
int begin,end;
begin = 10;
p = & begin;
end = *p;
printf("begin = %d\n",begin);
printf("end = %d\n",end);
printf("p=%d\n",p);
printf("*p=%d\n",*p);
}
begin = 10;p = & begin;end = *p;
movl $10, -8(%ebp) # begin
leal -8(%ebp), %eax # eax = &begin
movl %eax, -4(%ebp) # p = eax
movl -4(%ebp), %eax # eax = p
movl (%eax), %eax # eax = *p
movl %eax, -12(%ebp) # end = eax
&操作符取地址 , *操作符取对应地址的内容
printf("p=%d\n",p);
subl $8, %esp
pushl -4(%ebp)
pushl $LC2
call _printf
addl $16, %esp
printf("*p=%d\n",*p);
subl $8, %esp
movl -4(%ebp), %eax
pushl (%eax)
pushl $LC3
call _printf
addl $16, %esp
对比这两条语句传递的参数可见 p :-4(%ebp) ; *p : (-4(%ebp))。 在内存中存的变量是p. p是指向int 的指针, *p 是这个地址下对应的int .