Sams Teach Yourself C in 24 Hours

Sams Teach Yourself C in 24 Hours by Tony. Zhang Page A

Book: Sams Teach Yourself C in 24 Hours by Tony. Zhang Read Free Book Online
Authors: Tony. Zhang
Ads: Link
function, respectively. An integer variable, sum, is declared in line 13.
    The statement in line 15 calls the integer_add() function that you examined in the previous section. Note that two integer constants, 5 and 12, are passed to the integer_add() function, and that the sum variable is assigned the return result from the integer_add() function.
    05 067231861x CH03 4.10.2000 10:59 AM Page 51
    Learning the Structure of a C Program
    51
    You first saw the C standard library function printf() in Hour 2. If you thought you found something new added to the function in line 16, you’re correct. This time, there are two arguments that are passed to the printf() function. They are the string “The addition of 5 and 12 is %d.\n” and the variable sum.
    Note that a new symbol, %d, is added into the first argument. The second argument is the integer variable sum. Because the value of sum is going to be printed out on the screen, you might think that the %d has something to do with the integer variable sum. You’re right again. %d tells the computer the format in which sum should be printed on the screen.
    More details on %d are covered in Hour 4. The relationship between %d and sum is discussed in Hour 5, “Handling Standard Input and Output.”
    More importantly, you should focus on the program in Listing 3.2 and pay attention to how to call either a user-generated function or a standard C library function from the 3
    main() function.
    Summary
    In this lesson you learned the following important concepts and operators:
    • A constant in C is a value that never changes. A variable, on the other hand, can present different values.
    • A combination of constants, variables, and operators is called an expression in the C language. An expression is used to denote different computations.
    • The arithmetic operators include +, -, *, /, and %.
    • A statement consists of a complete expression suffixed with a semicolon.
    • The C compiler treats a statement block as a single statement, although the statement block might contain more than one statement.
    • The function type specified in the declaration of a function determines the type of the value returned by the function.
    • You have to follow certain rules to make a valid function name.
    • An argument contains information that you want to pass to a function. An argument list contains two or more arguments that are separated by commas.
    • The opening brace ({) and closing brace (}) are used to mark the start and end of a C function.
    • A function body contains variable declarations and statements.
    • Usually, a function should accomplish just one task.
    In the next lesson you’ll learn more about data types in the C language.
    05 067231861x CH03 4.10.2000 10:59 AM Page 52
    52
    Hour 3
    Q&A
    Q What is the difference between a constant and a variable?
    A The major difference is that the value of a constant cannot be changed, whereas the value of a variable can. You can assign different values to a variable whenever it’s necessary in your C program.
    Q Why do you need a statement block?
    A Many C keywords can only control one statement. A statement block provides a way to put more than one statement together, and put the statement block under the control of a C keyword. Then, the statement block is treated as a single statement.
    Q Which arithmetic operators have a higher precedence?
    A Among the five arithmetic operators, the multiplication, division, and remainder operators have a higher precedence than the addition and subtraction operators.
    Q How many parts does a function normally have?
    A A function normally has six parts: the function type, the function name, the arguments, the opening brace, the function body, and the closing brace.
    Workshop
    To help solidify your understanding of this hour’s lesson, you are encouraged to answer the quiz questions and finish the exercises provided in the workshop before you move to the next lesson. The answers and hints to the

Similar Books

The Chamber

John Grisham

Cold Morning

Ed Ifkovic

Flutter

Amanda Hocking

Beautiful Salvation

Jennifer Blackstream

Orgonomicon

Boris D. Schleinkofer