cout是右结合的
cout<<++a<<","<<a++;
的运行顺序是
1.a的值压栈
2.a自加
3.‘,’压栈
4.a自加
5.a的值压栈
6.输出栈中元素
int a[] = {1,3,5,7,9};
int * p = a;
cout<<a<<endl;
cout<<p<<" "<<*p<<endl; ---- 1
cout<<p<<" ";cout<<*p++<<endl; --- 1 , p--3
cout<<p<<" "<<*p++<<endl; --- 3 , p--5
cout<<p<<" "<<*++p<<endl; --- p--7 , 7
cout<<p<<" "<<(*p)++<<endl; --- 7 , 7+1;
cout<<p<<" "<<*p++<<endl; - ---- 8 , p--9;
结果:
0x0012FF6C
0x0012FF6C 1
0x0012FF6C 1
0x0012FF74 3
0x0012FF78 7
0x0012FF78 7
0x0012FF7C 8
Press any key to continue