You may have noticed that, in some of the programs listed earlier, the statements involving printf() spread over two lines. For example.
printf("The value of \"%d+%d*%d\" is %d\n",
z,x,y,z+x*y);
This is possible because the C language is a
free format
language, which means that statements and expressions may be written in any way to improve readability. This freedom also applies to the list of parameters for a function such as
printf()
and was used earlier to avoid long lines spoiling the appearance of the printed text. In general, C compilers regard any sequence of TAB characters, space characters and newline characters as equivalent to a single space. These are collectively known as white-space characters. Sequences of characters enclosed within the character pairs /* and */ are also equivalent to a single space. None of this applies to characters enclosed within double quotes.
It is also not permissible to write things such as
p r i n t f rather than
printf The reason is both interesting and important. As part of the compilation process the source program you have typed in is converted into a sequence of items known as tokens which might be names of variables, names of functions, keywords, operators or constants. The rules for identifying tokens are rather complicated to state but the effect is fairly obvious. The following example shows the "hello world" program listed one token per line
main
(
)
{
printf
(
"hello, world\n"
)
;
}
This was given as an example of how not to lay out programs in chapter 1. Breaking the name of a variable into separate pieces causes the compiler to see each piece as a separate token. Some equally bizarre looking examples of code can be understood by considering tokenisation. For example x-=-3 would be split into the token stream "x", "-=", "-" and "3", there being no other valid way of splitting it into tokens. It would have been better if the programmer had written
x -= -3 Oddities such as
x+++++y can probably only be validly tokenised as
x ++ + ++ y but it is much better to write the second form rather than the first.