!!!Formal Parameter & Actual Parameter & Pointer (形参, 实参, 指针)

来源:互联网 发布:农村淘宝新版下载安装 编辑:程序博客网 时间:2024/06/16 12:15

Formal Parameter vs Actual Parameter

Formal Parameter: 形参

Actual Parameter: 实参

The term parameter (sometimes called formal parameter) is often used to refer to the variable as found in the function definition, whileargument (sometimes calledactual parameter) refers to the actual value passed. To avoid confusion, it is common to view a parameter as a variable, and an argument as a value.

函数的形参和实参具有以下特点: 1. 形参变量只有在被调用时才分配内存单元,在调用结束时,即刻释放所分配的内存单元。因此,形参只有在函数内部有效。函数调用结束返回主调函数后则不能再使用该形参变量。 2. 实参可以是常量、变量、表达式、函数等,无论实参是何种类型的量,在进行函数调用时,它们都必须具有确定的值,以便把这些值传送给形参。因此应预先用赋值,输入等办法使实参获得确定值。 3. 实参和形参在数量上,类型上,顺序上应严格一致,否则会发生类型不匹配”的错误。 4. 函数调用中发生的数据传送是单向的。即只能把实参的值传送给形参,而不能把形参的值反向地传送给实参。 因此在函数调用过程中,形参的值发生改变,而实参中的值不会变化。 

Parameter & Pointer

Why we use Pointer as parameter: http://stackoverflow.com/questions/7054662/why-do-certain-c-c-functions-use-pointers-as-parameters

Simple Swapping function: http://www.cs.utsa.edu/~wagner/CS2213/swap/swap.html


原创粉丝点击