zoukankan      html  css  js  c++  java
  • C function

    C Primer Plus 5th Edition  page 270

    Many programmers like to think of a function as a "black box" defined in terms of the information that goes in(its input) and the value or action it

    produces(its output). What goes on inside the black box is not your concern, unless you are the one who has to write the string and ,perhaps, some arguments. You also know what output printf() should produce. You never have to think about the programming that went into creating printf() . Thinking of functions in this manner helps you concentrate on the program's overall design rather than the details. Think carefully about what the function should do and how it relates to the program a a whole before worrying about writing the code.

     Actual arguments and fomal parameters && a value from a function withreturn

    If we take C functions as back-boxes, thes boxes’ input are arguements and their output is the value returned

    Taking a black-box viewpoint, the main function connets all this functions by using  arguments (or parameters)  and returning value from these functions;if these functions are poins  like sand existing in space,then main function uses arguments and re-values to built different kinds of geometric figures.

     

    in page280:

    Functions should be declared by type. A function with a return value should be declared the same type as the return value. Functions with no return value should be declared as type void.

    Here is question: if a function has two or more return value ,how do we do ?

    why should we declare a function before we use it?

            To use a function correctly, a program needs to know the function type before the function is used for the first time. One way to accomplish this is to place the complete function defination aheah of its first use. However, this method could make the program harder to read. Also, the function might be part of the C library or in some other file. Therefore, we generally inform the compiler about functions by declaring them i advace.

    tags: the complete function defination , the advance funtion declaration

    in page 283:

    The calling function places its arguments in a temporay storage area called the stack,and the called function reads those arguements off the stack.

    The ANSI standard's solution to the problems of mismatched arguments is to permit the function declaration to declare the variable types,too. The result is a function prototype- a declaration taht states the return type, the number of arguements, and the types of those arguements.

     ----------------------------------------------

    These 2014.3.19 update

    ------------------------------------------------

    How to print the memery location:

    int n=0; 

    printf("%d %p",n,&n);

    what's the difference between error and warning?

    The difference between an error and a warning is that an error prevents compilation and a warning permits compilation. Some compilers make this type cast without telling you. That's because the standard doesn't require warnings.However, many compilers enalbe you to select a warning

    level that controls how verbose(啰嗦的) the compiler will be in issuing(流出,发表) warnings.

    Prototype

    Prototype are a string addition to the language. They enable the compiler to catch many errors or oversights you might make using a function.

    Other hand,we can no use the prototype when the function is short.

  • 相关阅读:
    为用户添加角色
    WCF、MongoDB
    文件分布式存储实现例程
    Redis的Replication(复制)
    Lucene热词显示并选择
    Lucene热词统计
    通过队列解决Lucene文件并发创建索引
    Lucene.net应用
    Lucene.net
    Redis
  • 原文地址:https://www.cnblogs.com/Micheal-G/p/3606970.html
Copyright © 2011-2022 走看看