C++算术运算符

124 阅读1分钟
#include<iostream>
using namespace std;

/*
算术运算符
前置递增和后置递增区别:前置递增先让变量+1再进行表达式运算;后置递增先进行表达式运算后让变量+1

*/

int main(){
    
    //两个小数可以相除,值也可以是小数
    double d1 = 3.14;
    double d2 = 1.2;
    cout << "d1/d2 = " << d1/d2 << endl;
    //两个小数是不可以做取模运算的
    double d3 = 3.14;
    double d4 = 1.2;
    cout << "d3/d4 = " << d3%d4 << endl;  //编译器提示报错

    //前置递增
    int a = 10;
    int b = ++a * 10;
    cout << "a = " << a << endl;
    cout << "b = " << b << endl;
    //后置递增
    int c = 10;
    int d = ++c * 10;
    cout << "c = " << c << endl;
    cout << "d = " << d << endl;
    
    system("pause");
    return 0;
}