void interchange(int * u,int * v)
{
int temp = *u; //带*号指向该地址上的值
*u = *v;
*v = temp;
}
int main1(void)
{
int x = 10;
int y = 5;
printf("before: x = %d y = %d\n",x,y);
interchange(&x,&y);
printf("after: x = %d y = %d\n",x,y);
}
结果:
int sump(int *start, int *end)
{
int total = 0;
while(start < end)
{
total += *start;
printf("%3d",*start);
start++; //每次移动int类型大小的位置
}
printf("\n");
return total;
}
int main(void)
{
int x[6] = {10,4,2,6,8,12};
int sum;
sum=sump(x,x+6);
printf("%3d\n",sum);
}
结果: