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.

 

转载于:https://www.cnblogs.com/Micheal-G/p/3606970.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值