*p为什么是0而不是输入的最后一个数5
#include<stdio.h>
int main(void)
{
int a[10],*p,sum=0;
printf("Enter inter");
for(p=a;p<a+5;p++){
scanf("%d",&*p);
sum=sum+*p;
}
printf("sum=%d ",sum);
printf("*p=%d",*p);
return 0;
}
-------------------------
Enter inter1 2 3 4 5
sum=15
*p=0
--------------------------------
Process exited after 3.542 seconds with return value 0
请按任意键继续. .
for 循环后p再加了一次,最后指向的是a[5]而不是存放‘5’的a[4],你可以在printf("*p=%d",*p);前面加一句p--;就得到5了。
热门标签: