例8-7分别使用数组和指针计算数组元素之和int main(void)地址内容数组元素 inti, a[10], *p;p3000long sum = 0;aa[0]printf("Enter 10 integers: ");pa+13002a[1]for(i = 0; i< 10; i++)scanf("%d", &a[i])pa+ia[]for(i= 0; i< 10; i++)sum=sum+a[i];printf("calculated by array,a+93018a[9]psum=%ld In", sum);sum=0;for(p = a; p<= a+9; p++)Enter10integers:10987654sum= sum+*p;321printf("calculated by pointer,calculated by array, sum=55sum=%ld In",sum);return 0;calculated by pointer, sum=551int main(void) { int i, a[10], *p; long sum = 0; printf("Enter 10 integers: "); for(i = 0; i < 10; i++) scanf("%d", &a[i]); for ( i = 0; i < 10; i++) sum = sum + a[i]; printf("calculated by array, sum=%ld \n", sum); sum=0; for(p = a; p <= a+9; p++) sum = sum + *p; printf("calculated by pointer, sum=%ld \n", sum); return 0; } 例8-7 分别使用数组和指针计算数组元素之和 Enter 10 integers: 10 9 8 7 6 5 4 3 2 1 calculated by array, sum=55 calculated by pointer, sum=55 p 3000 a[0] 地址 内容 数组元素 3002 a[1] 3018 a[9] a[i] a a+1 a+9 a+i p p p