Wednesday, January 4, 2012

Is it necessary to use different lines in writing code?

A white-space character, such as that created when you press the Enter key, used between tokens is invisible to the C compiler. Therefore, you have the freedom to write C code at any row or column you like. The C compiler, for example, allows you to rewrite and pack into one line:

#include void main(void){printf("This is C!");}

or rewrite it as

#include

void main(void)
{
printf("This is C!");
}

However, these styles will make your program more difficult to understand and should not be used.

There is no required form for spacing within your programs. However, your instructor or employer may want you to adhere to certain standard accepted styles. Our example programs are meant to illustrate acceptable style, however, at times, publishing constraints do not allow us to follow any one accepted style rigorously. Indentation and spacing are considered important for the look of a program, even though they do not affect performance. To make your program readable, do such things as write one statement per line, line up your braces, and add blank lines where there are natural breaks in code instructions.

No comments:

Post a Comment