运算符同优先级的运算

#include<iostream>
using namespace std;
int main()
{
    int x1=0;
    int x2=0;
    int a1,a2;
    cout<<"x1="<<x1<<endl;
    cout<<"x2="<<x2<<endl;
    a1=!x1++;
    //先执行!x1,x1=0,x1!=1成立,所以整个式子的值为true=1
    a2=!++x2;
    //先执行++x2,x2=1,x2!=1不成立,所以整个式子的值为true=0
    cout<<"a1="<<a1<<endl;
    cout<<"a2="<<a2<<endl;
    return 0;
}

在这里插入图片描述
运算符优先级及运算次序参考博客
http://www.slyar.com/blog/c-operator-priority.html

同一优先级的运算符,运算次序由结合方向所决定。

猜你喜欢

转载自blog.csdn.net/qq_34941153/article/details/90046634