++ 优先级大于 * ,离变量距离相同
eg: *p++,指针自增
其他情况,谁离变量近先算谁
eg:*++p和++*p,前者指针自增,后者值自增
// *p++
void test()
{
cout << "_____*p++_____" << endl;
int a[3] = {1,3,5};
int* p = a;
cout << "*p : " << *p << endl;
cout << "*p++: " << *p++ << endl;
cout << "*p : " << *p << endl;
}
// (*p)++
void test(int a)
{
cout << "_____(*p)++_____" << endl;
int b[3] = { 1,3,5 };
int* p = b;
cout << "*p : " << *p << endl;
cout << "(*p)++: " << (*p)++ << endl;
cout << "*p : " << *p << endl;
}
// *++p
void test(int a, int b)
{
cout << "_____*++p_____" << endl;
int c[3] = { 1,3,5 };
int* p = c;
cout << "*p : " << *p << endl;
cout << "*++p : " << *++p << endl;
cout << "*p : " << *p << endl;
}
// ++*p
void test(int a, int b,int c)
{
cout << "_____++*p_____" << endl;
int d[3] = { 1,3,5 };
int* p = d;
cout << "*p : " << *p << endl;
cout << "++*p : " << ++*p << endl;
cout << "*p : " << *p << endl;
}
int main()
{
cout << " p -> {1, 3, 5} " << endl;
test();
test(1);
test(1, 1);
test(1, 1, 1);
return 0;
}
运行结果: