Table 4-1
Data Types in C
One thing to consider is that if
data types exceed their range, then strange things
happen. So, if you have a byte variable with 255 in it and you add 1 to it, you get 0. More
alarmingly, if you have an
int
variable with 32767 and you add 1 to it,
you will end up
with −32768.
Until you are completely comfortable with these different data types, I would
recommend sticking to
int
, as it works for pretty much everything.
Coding Style
The C compiler does not really care about how you lay out your code. For all it cares, you
can write everything on a single line with semicolons between each statement. However,
well-laid-out, neat code is much easier to read and maintain than poorly laid-out code. In
this sense, reading code is just like reading a book: Formatting is important.
To some extent, formatting is a matter of personal taste. No one likes to think that he
has
bad taste, so arguments about how code should look can become personal. It is not
unknown for programmers, on being required to do something with someone else’s code,
to start by reformatting all the code into their preferred style of presentation.
As
an answer to this problem, coding standards are often laid down to encourage
everyone to lay out his or her code in the same way and adopt “good practice” when
writing programs.
The C language has a de facto standard that has evolved over the years, and this book is
generally faithful to that standard.
Indentation
In the example sketches that you have seen, you can see that we often indent the program
code from the left margin. So,
for example when defining a
Dostları ilə paylaş: