comma separated expression in while loop in C

前端 未结 5 1924
慢半拍i
慢半拍i 2020-11-30 07:50

I never saw such a while statement before.

while(printf(\"> \"), fgets(str, 100, stdin), !feof(stdin)) {
..
..
}

I read

5条回答
  •  北海茫月
    2020-11-30 08:34

    The comma operator is best thought of as, well, an operator. Just like + is an operator, so that 2 + 3 is an expression (which happens to result in a value of 5), so too , is an operator, and thus 0, 1 is a valid expression (which happens to result in a value of 1, since that was the last operand).

提交回复
热议问题