How does these expressions evaluate?

int main() {
    int a=5,b=-7,c=0,d;
     d= ++a && ++b || c++;
    
    cout<<a<<"t"<<b<<"t"<<c<<"t"<<d<<"n";
    
    int x = 1,y =0,z=5;
    
    int e = x&&y||z++;
    cout<<x<<"t"<<y<<"t"<<z<<"t"<<e<<"n";
    int f = x&&y&&z++;
    cout<<x<<"t"<<y<<"t"<<z<<"t"<<f<<"n";
    
    int g = x&& y&& ++z;
    cout<<x<<"t"<<y<<"t"<<z<<"t"<<g<<"n";
    
    int h = x&& y|| ++z;
    cout<<x<<"t"<<y<<"t"<<z<<"t"<<h;
    return 0;
}



//***OUTPUT***

// 6    -6  0   1

// 1    0   6   1

// 1    0   6   0

// 1    0   6   0

// 1    0   7   1

In the above mentioned output the value of c has not been incremented after the first expression is evaluated. While the value of z increments in the 2nd and last expression . Any logical reason for such anomaly?

Source: Windows Questions C++

LEAVE A COMMENT