对于刚接触C/C++来说,++a a++ 和 --a a--或许会有些迷糊.
++(递增运算符) --(递减运算符) 各有两种出现形式 根据运算符的位置分为前缀和后缀形式
a++ b-- 属于后缀形式 ++a --b 属于前缀形式
先程序根据结果我们再去分析:
#include <iostream>
using namespace std;
const int ArSize = 16;
int main()
{
int a =10;
int b= 10;
cout << "++++++++++++++++Begin++++++++++++++++"<<endl;
cout<<"a = "<<a<<endl;
cout <<"a++ = "<<a++<<endl;
cout << "a = " <<a<<endl;
cout <<"***********a++和++a的分割线****************"<<endl;
cout <<"++a = "<<++a<<endl;
cout <<"a = "<< a <<endl;
cout << "++++++++++++++++++End++++++++++++++++"<<endl;
cout << "----------------Begin----------------"<<endl;
cout << "b = " << b << endl;
cout << "b-- = " << b-- << endl;
cout << "b = " << b << endl;