码迷,mamicode.com
首页 > 其他好文 > 详细

Functions

时间:2014-10-04 23:58:17      阅读:259      评论:0      收藏:0      [点我收藏+]

标签:des   io   os   ar   for   sp   art   c   on   

1 Local static variables

Local static variables are not destroyed when the function ends; they are destroyed when the program terminates.

2. Function parameter list

Parameter names are optional. However, there is no way to use an unnamed parameter. And a call must supply  an argument for all parameter, even if the parameter is not used.

3. Function return type

The return type can be void, which means the function doesn‘t return a value. However, the return type can be an array type or a fucntion type. 

4. Scope of a name and lifetime of an object

The scope of a name is the part of program text in which the name is visible. The lifetime of an object is the time during program‘s execution that the object exists.

5. Why function declaration goes in header files?

When we use header files for our function declaration, we can ensure that all the declarations for a given function agree. Moreover, if the interface to the function changes, only one declaration has to be changed.

6. Two usage of passing arguments by reference

1) Using reference to avoid copies.

2) Using reference parameters to return additional information

7. Arguments in main function

When we use the arguments in argv, remember that the optional arguments begin at argv[1]; argv[0] contains the program‘s name not user input.

8. Functions with varying number of parameters

Under new standard, we can pass a library type named initializer_list if the arguments have the same type. If the argument types vary, we can write a special kind of function known as variadic template.

9. Never return a reference or a pointer to a local variable

10. Overloaded function

Functions that have the same name but different parameter lists and that appear in the same scope are overloaded. 

11. Overload and const

Top-level const parameter and non-const parameter is not distinguishable in function overloading whereas low-level const will.

12. Default arguments

Some functions have parameters that are given a particular value in most, but not all calls. In such cases, we can declare that common value as a default argument for the function. Functions with default argument can be called with or without that argument.

13. Function type

A function‘s type is determined by its return type and paramter list. The function‘s name is not part of its type. 

14. Function pointer

When call a function by a function pointer, we can both dereference the pointer or not. Both ways are ok.

 

Functions

标签:des   io   os   ar   for   sp   art   c   on   

原文地址:http://www.cnblogs.com/Kai-Xing/p/4005121.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!