Page 32 - Programming Microcontrollers in C
P. 32
Character Constants 17
Often you will want to leave “clues” as to what the program or
line of code is supposed to do. Comments within the code provide
this documentation. A C comment is delimited by
/* . . . . . . . */
and the comment can contain anything except another comment. In
other words, comments may NOT be nested. The first line of code
in the above program is a comment, and the sixth line contains both
code and a comment. The compiler ignores all information inside
the comment delimiters.
This program uses two integer variables c and nl. The variable
c is the temporary storage location in which input data are stored,
and nl is where the number of input lines are counted.
The while statement contains a rather complicated argument.
At any point in a C program when a value is calculated, it can be
stored in a specified location. For example, in the while expression
while((c=getchar()) != EOF)
the inner expression
c=getchar()
causes the function getchar() to be executed. The return from
getchar() is a character from the input stream. This character is
assigned to the variable c. After this operation is completed, the re
sult returned from getchar() is compared with the constant EOF.
EOF means end-of-file, and it is the value returned by getchar()
when a program tries to read beyond the end of the data stream. It is
defined in the file stdio.h. The symbol != is read “is not equal
to.’’ Therefore, the argument of the while will be TRUE so long as
getchar() does not return an EOF and the statement following
the while will be continually executed until an EOF is returned.
Operators in an expression that have the higher precedence will be
executed before the lower precedence operators. In the expression
c= getchar() != EOF
the operator != has a higher precedence than that of the = operator.
Therefore, when this expression is evaluated, the logical portion of
the expression will be evaluated first, and the result of the logical