//这里说明了指针和数组的不同
//ar本身并不是一个数组,它是一个指向marbles首元素的指针
#include<stdio.h>
#include<stdlib.h>
#define SIZE 10
int sum(int ar[],int n);
int main() {
int marbles[SIZE]={20,10,5,39,4,16,19,26,31,20};
long answer;
answer=sum(marbles,SIZE);
printf("The total number of marbles is %ld.\n",answer);
printf("The size of is %d bytes.\n",sizeof marbles);
system("pause");
return 0;
}
int sum(int ar[],int n){
int i;
int total=0;
for(i=0;i<n;i++)
total+=ar[i];
printf("The size of ar is %d bytes.\n",sizeof ar);
return total;
}
数组和指针的区别
最新推荐文章于 2024-05-22 23:15:24 发布