Sams Teach Yourself C in 24 Hours

Free Sams Teach Yourself C in 24 Hours by Tony. Zhang

Book: Sams Teach Yourself C in 24 Hours by Tony. Zhang Read Free Book Online
Authors: Tony. Zhang
numbers at all. In fact, if you do enter the line numbers in the listing, your program will not work! So when you enter these programs, remember not to enter the line numbers that are shown in the book.
    Two things you might notice by glancing at Listing 2.1 are the semicolons and indenting on lines 6 and 7. Unlike other languages, such as BASIC, the end of a line has no special significance in C. It is perfectly legal (and in many cases, advisable) to break a statement into several lines for clarity.
    Generally, an individual C statement ends in a semicolon, but there is more about this later in the book. The indenting serves to identify the various lev-04 067231861x CH02 1/25/00 10:42 AM Page 29
    Writing Your First C Program
    29
    els of a program in a kind of outline format. The function main() is, well, the main level of the program, so it goes on the far left. Lines 6 and 7 are part of main() so they are indented one level to the right. Usually, you use your Tab key to indent a level before you start typing. It should be noted that indenting, like line numbers, is not enforced — or even noticed! — by the compiler. The programmer is free to use line breaks and indenting, commonly referred to as whitespace , to make the program look readable. It is generally a matter of style, but it’s a good idea to follow generally accepted 2
    conventions so that other programmers can understand your programs and
    vice-versa. Take a look at the use of whitespace in the programs in this book, and feel free to develop your own style as you go.
    I set up my development environment in such a way that all C programs in this book can be compiled and made into console applications. For instance, 02L01.exe is the name of the console application made from 02L01.c. Note that .exe is included as the extension to the name of a DOS or Windows application program (that is, an executable file).
    Also, on my machine, I save all the executable files made from the C programs in this book into a dedicated directory called C:\app. Therefore, if I type in 02L01 from a DOS
    prompt and press the Enter key, I can run the 02L01.exe executable file and display the message Howdy, neighbor! This is my first C program. on the screen. The following output is a copy from the screen:
    Howdy, neighbor! This is my first C program.
    OUTPUT
    Comments
    Now let’s take a close look at the C program in Listing 2.1.
    The first line contains a comment:
    /* 02L01.C: This is my first C program */
    You notice that this line starts with a combination of slash and asterisk, /*, and ends with
    */. In C, /* is called the opening comment mark , and */ is the closing comment mark .
    The C compiler ignores everything between the opening comment mark and closing comment mark. That means the comment in the first line of Listing 2.1, 02L01.C: This is my first C program, is completely ignored by the compiler.
    The only purpose of including comments in your C program is to help you document what the program or some specific sections in the programs do. Remember, comments are written for yourself and other programmers. For example, when you read someone else’s 04 067231861x CH02 1/25/00 10:42 AM Page 30
    30
    Hour 2
    code, the comments in the code help you to understand what the code does, or at least what the code intends to do. As your programs get larger and more complicated, you can use comments to write notes to yourself about what you are trying to do and why.
    You don’t need to worry about the size or performance speed of your C program if you add many comments into it. Adding comments into a C program does not increase the size of the binary code of the program (that is, the executable file), although the size of the program itself (that is, the source code) may become larger. The performance speed of the executable file made from your C program is not affected in any way by the comments inside your C program.
    The C language allows you to write a comment that crosses more than

Similar Books

Skin Walkers - King

Susan Bliler

A Wild Ride

Andrew Grey

The Safest Place

Suzanne Bugler

Women and Men

Joseph McElroy

Chance on Love

Vristen Pierce

Valley Thieves

Max Brand