#include <iostream>
using namespace std;
int main()
{
int a = 2;
int b = ++a*2;//前置递增(先变量+1,再进行运算)
cout <<"a的值" << a << endl;
cout << "b的值" << b << endl;
system("pause");
return 0;
}
2.后置递增运算符:(先表达式运算,后变量+1)
#include <iostream>
using namespace std;
int main()
{
int a = 2;
int b = a++ * 2;//后置递增(先运算,再进行变量+1)
cout <<"a的值" << a << endl;
cout << "b的值" << b << endl;
system("pause");
return 0;
}
递减运算符:(让变量-1)
1.前置递减:(变量先-1,再进行运算)
// 练习.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
using namespace std;
int main()
{
int a = 2;
int b = --a * 2;//后置递增(先变量-1,再进行运算)
cout <<"a的值" << a << endl;
cout << "b的值" << b << endl;
system("pause");
return 0;
}
2.后置递减:(先运算,再进行变量-1)
#include <iostream>
using namespace std;
int main()
{
int a = 2;
int b = a-- * 2;//后置递减(先运算,再进行变量-1)
cout <<"a的值" << a << endl;
cout << "b的值" << b << endl;
system("pause");
return 0;
}