go to previous page   go to home page   go to next page

Answer:

The parentheses around the assignment expression (in red) are needed because assignment has lower precidence than !=.

while ( (ch = getchar()) != EOF ) 

Without the red parenthese, the statement would work as if it were written like this:

while ( ch = (getchar() != EOF) ) 

which would assign either a 0 (for false) or a 1 (for true) to ch.


Example Dialog

But, soft! what light through yonder window breaks?

Above is an example of the program working, with input from the keyboard and output to the monitor.


QUESTION 11:

Could this program be used as it is with input from a text file and output to a text file?