#include<stdio.h>
#include<stdlib.h>
int main()
{
int arr[]={6,7,8,9,10};
int *ptr=arr;
*(ptr++)+=123;
printf("%d,%d\n",*ptr,*(++ptr));
system("pause");
return 0;
}
此程序输出结果为:8,8
第一个坑在于:注意自增运算符++;
第二个坑在于c中的printf函数计算参数时是从右到左计算参数的。
*(ptr++)+=123; 相当于 *ptr+=123;ptr++;
printf("%d,%d\n",*ptr,*(++ptr)); 此句先计算*(++ptr);再计算*ptr;