Cần giải thích toán tử điều kiện ? :

 #include <stdio.h>
    int main()
    {
        int y = 1, x = 0;
        int l = (y++, x++) ? y : x;
        printf("%d\n", l);
    } 

e chưa rõ lăm về toán tử này có ai giải thích hộ em. em xin cảm ơn !!

Nó tương đương với

int l;
if ((y++, x++)) l = y; else l = x;

Về dấu phẩy:

The comma operator (represented by the token, ) is a binary operator that evaluates its first operand and discards the result, it then evaluates the second operand and returns this value (and type). The comma operator has the lowest precedence of any C operator, and acts as a sequence point.

5 Likes

cảm ơn nhiều cứ nghĩ nó là

if ((y++))
l=y;
else if ((x++))
l=x;
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?