[prev] 63 [next]

Exercise 5: Assignment as Expression

In the example above, we wrote:

// read stdin one char at-a-time
while ((ch = getchar()) != EOF) {
   // do something with ch
}

which reads a char into ch and tests it against EOF

What would the following code do?

// read stdin one char at-a-time
while  ( ch = getchar() != EOF)  {
   // do something with ch
}

Hint: Check precedence table in the C Reference Card or by typing the command

man 7 operator