C++经常会被问到的一个小知识,今天彻底搞懂了
举例子说明
#include <iostream>
using namespace std;
int main()
{
int a[4] = { 1, 2, 3 ,4};
int *p = a;
cout << *p++ << endl;//先让指针p自增1,然后再取p指向的值,要注意后自增性,取的仍然是a[0]的值(右结合性,后自增性)
cout << *++p << endl;
cout << *(++p) << endl;
cout << *(p++) << endl;
int i = 2;
cout << -i++ << endl;
cout<<-++i<<endl;
cout << i << endl;
return 0;
}
运行结果