*p++ // same as *(p++): increment pointer, and dereference unincremented address
*++p // same as *(++p): increment pointer, and dereference incremented address
++*p // same as ++(*p): dereference pointer, and increment the value it points to
(*p)++ // dereference pointer, and post-increment the value it points to
Remembering operator precedence rules, we can recall that postfix operators, such as increment and decrement, have higher precedence than prefix operators, such as the dereference operator (*
)
后缀 优先级大于 前缀
For example(*++p):
// more pointers
#include <iostream>
using namespace std;
int main()
{
int arr[5] = { 1,3,5,7,9 };
int* p = arr;
int b;
b = *++p;
cout << "b: " << b << " *p: " << *p << endl;
return 0;
}
outpu:
b: 3 *p: 3