Assigning value in while loop condition

c, initialization, while-loop

Solution

The comma operator is a binary operator that evaluates its first operand and discards the result, it then evaluates the second operand and returns this value.

It is also a "sequence point", which means that all side effects will be calculated before the next part of the code is executed.

Problem

I found this piece of code on Wikipedia. ``` #include <stdio.h> int main(void) { int c; while (c = getchar(), c != EOF && c != 'x') { switch (c) { case '\n': case '\r': printf ("Newline\n"); break; default: printf ("%c",c); } } return 0; } ``` I'm curious about expression used as condition for while loop: ``` while (c = getchar(), c != EOF && c != 'x') ``` It's quite obvious what it does, but I've never seen this construction before. Is this specific to while loop? If not, how does parser/compiler determine which side of comma-separated expression returns boolean value for while loop?

Original source