Sams Teach Yourself C in 24 Hours

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

Book: Sams Teach Yourself C in 24 Hours by Tony. Zhang Read Free Book Online
Authors: Tony. Zhang
Ads: Link
questions and exercises are given in Appendix D, “Answers to Quiz Questions and Exercises.”
    Quiz
    1. In the C language, is 74 a constant? How about 571?
    2. Is x = 570 + 1 an expression? How about x = 12 + y?
    3. Are the following function names valid?
    2methods
    m2_algorithm
    *start_function
    Room_Size
    .End_Exe
    _turbo_add
    4. Is 2 + 5 * 2 equal to (2 + 5) * 2?
    5. Does 7 % 2 produce the same result as 4 % 3?
    05 067231861x CH03 4.10.2000 10:59 AM Page 53
    Learning the Structure of a C Program
    53
    Exercises
    1. Given two statements, x = 3; and y = 5 + x;, how can you build a statement block with the two statements?
    2. What is wrong with the following function?
    int 3integer_add( int x, int y, int z)
    {
    int sum;
    sum = x + y + z;
    return sum;
    }
    3. What is wrong with the following function?
    int integer_add( int x, int y, int z)
    {
    int sum;
    3
    sum = x + y + z
    return sum;
    }
    4. Write a C function that can perform a multiplication of two integers and return the calculated result.
    5. Write a C program that calls the C function you just wrote in Exercise 4 to calculate the multiplication of 3 times 5 and then print out the return value from the function on the screen.
    05 067231861x CH03 4.10.2000 10:59 AM Page 54

    06 067231861x CH04 4.10.2000 11:00 AM Page 55
    HOUR 4
    Understanding Data
    Types and Keywords
    What’s in a name? That which we call a rose
    By any other name would smell sweet.
    —W. Shakespeare
    You learned how to make a valid name for a C function in Hour 3,
    “Learning the Structure of a C Program.” Now, you’re going to learn more about naming a variable and the C keywords reserved by the C compiler in this hour.
    Also in this hour you’re going to learn about the four data types of the C
    language in detail:
    • char data type
    • int data type
    • float data type
    • double data type
    06 067231861x CH04 4.10.2000 11:00 AM Page 56
    56
    Hour 4
    C Keywords
    The C language reserves certain words that have special meanings to the language. Those reserved words are sometimes called C keywords . You should not use the C keywords for your own variable, constant, or function names in your programs. Table 4.1 lists the 32
    reserved C keywords.
    TABLE 4.1
    Reserved Keywords in C
    Keyword
    Description
    auto
    Storage class specifier
    break
    Statement
    case
    Statement
    char
    Type specifier
    const
    Storage class modifier
    continue
    Statement
    default
    Label
    do
    Statement
    double
    Type specifier
    else
    Statement
    enum
    Type specifier
    extern
    Storage class specifier
    float
    Type specifier
    for
    Statement
    goto
    Statement
    if
    Statement
    int
    Type specifier
    long
    Type specifier
    register
    Storage class specifier
    return
    Statement
    short
    Type specifier
    signed
    Type specifier
    sizeof
    Operator
    static
    Storage class specifier
    struct
    Type specifier
    switch
    Statement
    06 067231861x CH04 4.10.2000 11:00 AM Page 57
    Understanding Data Types and Keywords
    57
    Keyword
    Description
    typedef
    Statement
    union
    Type specifier
    unsigned
    Type specifier
    void
    Type specifier
    volatile
    Storage class modifier
    while
    Statement
    Don’t worry if you can’t remember all the C keywords the first time through. In the rest of the book, you’ll become more familiar with them and start to use many of the keywords through examples and exercises.
    Note that all C keywords are written in lowercase letters. As I’ve mentioned, C is a case-sensitive language. Therefore, int, as shown in the list here, is considered as a C keyword, but INT is not.
    The char Data Type
    4
    An object of the char data type represents a single character of the character set used by your computer. For example, A is a character, and so is a. But 7 is a number.
    However, a computer can only store numeric code. Therefore, characters such as A, a, B, b, and so on all have a unique numeric code that is used by computers to represent the characters. Usually, a character takes 8 bits (that is, 1 byte) to store its numeric code.
    For many computers,

Similar Books

Commencement

Alexis Adare

Mission of Hope

Allie Pleiter

Last Seen Leaving

Caleb Roehrig

My Juliet

John Ed Bradley

Delia of Vallia

Alan Burt Akers

Tomorrow War

Mack Maloney