<Practical C Programming> chapter 4

<Practical C Programming>                                                                                        chapter 4
1. Elements of a program:
    In computer programming, you need two things: data(variables) and instructions (code or functions).
    variables are the basic building blocks of a program;
    Instructions tell the computer what to do with the variables.
    Comments are used to describle the variable and instructions.
2. Basic Program Structure:
    the basic element of a program are the data declarations, functions, and comments.
    the basic structure of a one-function program is:

/****************************************************
 * ...Heading comments...
 *
 ****************************************************/
...Data declarations...
int main()
{
    ...Executable statements...
    return (0);
}



    Heading comments tell the programmer about the programm, and the data declartions describe the data that the program is going to use.
    the single function is named main, a special one, because it's the first function called. the function main begins with:
        int main()
        {
    and ends with:
            return (0);
        }
    a non-zero status indicates an error--the bigger the return value, the more severe the error.
3. Simple Expressions:
    simple operations:
        operator    meaning
        *        multiply
        /        divide
        +        add
        -        substract
        %        modulus (return the remainder after division)
    *, /, and % have precedence over + and -. Parentheses, (), may be used to group terms.
4. Variable and storage:
    C allow us to store values in variables. each variable is identified by a variable name. in addition, each variable has a variable type.
    Names start with a letter or underscore(_), followed by any number of letters, digits, or underscores.
    Case-sensitive.
    Avoid variable names that similar, for they're confusing.
5. Variable Declarations:
    A variable declaration serves three purposes:
        1. It defines the name of the variable;
        2. It defines the type of the variable;
        3. It gives the programmer a description of the variable.
    The general form of a variable declaration is:
        type  name; /* comment */
    where tyoe is one of the C variable types and name is any valid variable name. this declaration explains what the variable is and what it will be used for.
6. Intergers
    int name; /* comment */
    limits.h
7. Assignment statements:
    =
    the general form of the assignment statement is:
        variable = expression;
8. printf function:
    printf(format, expression-1, expression-2, ...);
    where format is the string describing what to print;
9. floating point:
    float variable; /* comment */
10. Floating point versus integer divide:
    expression    result
    int / int             int
    float / int         float
    int / float         float
    float / float      float
11. characters:
    char variable; /* comment */
    the backslash character (\) is called the escape character, it is used to signal that a special character follows;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值