大家说说函数的“形参”与“实参”的区别

do__i 2011-11-11 05:55:47
我知道的是:

形参类似于局部变量,在函数的形参表中定义,由被调用时调用函数的实参初始化。

实参可以是变量、字面值常量或表达式。实参的类型必须与形参的类型及个数匹配。
...全文
274 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
kissydrink 2011-11-12
  • 打赏
  • 举报
回复
形参只是告诉你函数需要什么形式的参数;实参就是传给函数实际的参数了,类型要符合形参的类型。
hjy_x 2011-11-12
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 tianyahaijiaozd 的回复:]

形参只有在函数调用的时候才在栈分配地址空间并用实参的值来初始化,这是它俩最本质的差别和联系!
[/Quote]
++
woshiwaiwai 2011-11-12
  • 打赏
  • 举报
回复
形参 用于函数声明和定义的时候
实参 就是我们在调用函数的时候传进去的参数
机智的呆呆 2011-11-11
  • 打赏
  • 举报
回复
ISO/IEC 14882:2003(E)

1.3.1. argument
an expression in the comma-separated list bounded by the parentheses in a function call expression, a sequence of preprocessing tokens in the comma-separated list bounded by the parentheses in a function-like macro invocation, the operand of throw, or an expression, type-id or template-name in the commaseparated list bounded by the angle brackets in a template instantiation. Also known as an actual argumentor actual parameter.

1.3.9 parameter [defns.parameter]
an object or reference declared as part of a function declaration or definition, or in the catch clause of an exception handler, that acquires a value on entry to the function or handler; an identifier from the commaseparated
list bounded by the parentheses immediately following the macro name in a function-like macro definition; or a template-parameter. Parameters are also known as formal arguments or formal parameters.
bo_boface 2011-11-11
  • 打赏
  • 举报
回复
个人觉得形参就像方程中的代数X之流,实参就是具体的数据
tzqin 2011-11-11
  • 打赏
  • 举报
回复
“形参”就是个形式,然后调用时用“实参”来填充。“形参”用“抽象”来形容,“实参”用“具体”来形容
dq 2011-11-11
  • 打赏
  • 举报
回复
形参只有在函数调用的时候才在栈分配地址空间并用实参的值来初始化,这是它俩最本质的差别和联系!
万里 2011-11-11
  • 打赏
  • 举报
回复
同意一楼的解释
bdlzhx 2011-11-11
  • 打赏
  • 举报
回复
形参:形式参数,一般是数据类型,没有具体值;
实参:函数调用时需要传入的实际值;
不知道还有没有别的区别。
yanshuangying223 2011-11-11
  • 打赏
  • 举报
回复
听听高见
iamnobody 2011-11-11
  • 打赏
  • 举报
回复
个人见解。。。。
iamnobody 2011-11-11
  • 打赏
  • 举报
回复
举个例子说明一下吧:

class A;

void fun(A a){
};
void main(){
A b;
fun(b);//这一句相当于: A a = b;或者 A a(b);//a 是形参,属于fun()里面的局部变量,对任何类型的A和任何类型的表达式b,都有效,括 A是 引用,是指针的情况。
}
Roy_Smiling 2011-11-11
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20111104/12/c18e3061-2246-48a7-b127-6bcb966c11b7.html
彭家老三 2011-11-11
  • 打赏
  • 举报
回复
沙发,坐等高人解释。

64,653

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧