Does <execution have priority over ==?

For the following code:

int main()
{
    int a, b, c, d;
    c = 5;
    d = 5;
    a = 10;
    b = 8;
    if (a == c++ && b < d++);
    printf("c=%d d=%d\n", c, d);
    return 0;
}

Output: c=6 d=5

I know, since the first expression in the if expression takes the value false, the second expression is not evaluated and therefore is output. However, I read the following words in ANSI C from Balaguruswamy:

Since the operator <has a higher priority than ==, b < d++first evaluated, and then a == c++.

Now, according to this, the value dshould not be 6, but not c?

+3
source share
6 answers

. , , ( : C primer plus), && || . b < d++ a == c++ is false (- &&). d , 5.

+4

, .

a == c++ && b < d++ (a == c++) && (b < d++) - . , , , . 1

- , , . - , , .


1 , , . , (a*b)+(c-d), a*b c-d , +. - , , +, . , , a*b c-d , * , -.

+4

false && anything false, , false, , . a d .


: .

+2

< ==, b < d ++ , == ++.

, .

a == c++ , true (.. != 0), b < d++.

+2

, , d ++ . → .

.

0

< ==

-3

All Articles