一、递增递减
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
using namespace std;
int main()
{
//1、前置递增
int a = 10;
++a; //让变量+1
cout << "a=" << a << endl;
//2、后置递增
int b = 10;
b++;
cout << "b=" << b << endl;
//3、前置和后置的区别
//前置递增,先让变量+1,然后进行表达式运算
int a2 = 10;
int b2 = ++a2 * 10;
cout << "a2=" << a2 << endl; //11
cout << "b2=" << b2 << endl; //110
//后置递增,先进行表达式运算,后让变量+1
int a3 = 10;
int b3 = a3++ * 10;
cout << "a3=" << a3 << endl; //然后10++变为11
cout << "b3=" << b3 << endl; //10先运算100
//4、后置递减同理
system("pause");
return 0;
}
运行结果:文章来源地址https://www.toymoban.com/news/detail-819335.html
a=11
b=11
a2=11
b2=110
a3=11
b3=100
文章来源:https://www.toymoban.com/news/detail-819335.html
到了这里,关于三、C++运算符(2)算数运算符的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!