功能参数的描述 [英] A description of function parameters

查看:69
本文介绍了功能参数的描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有以下代码:


void foo(int some_int);

.....

int x = 5;

foo(x);

.....


void foo(int some_int)

{

printf("%d \ n",some_int);

}


''some_int'会被视为局部变量,(恰好是外部初始化的
)?如果没有,它会被视为什么?

Say I have the following code:

void foo(int some_int);
.....
int x = 5;
foo(x);
.....

void foo(int some_int)
{
printf("%d\n", some_int);
}

Would ''some_int'' be considered a local variable, (which happens to be
initialised externally)? If not, what would it be considered as?

推荐答案




Rob Somers写道:


Rob Somers wrote:
说我有以下代码:

void foo(int some_int);
....
int x = 5;
foo(x);
....

void foo(int some_int)
{/> printf("%d \ n",some_int );
}


将'some_int'视为局部变量(恰好是外部初始化的)?如果没有,会被视为什么?
Say I have the following code:

void foo(int some_int);
....
int x = 5;
foo(x);
....

void foo(int some_int)
{
printf("%d\n", some_int);
}

Would ''some_int'' be considered a local variable, (which happens to be
initialised externally)? If not, what would it be considered as?



是的some_int将被认为是本地的,如果它是初始化的,那么它会更好。
外部的
。此外,一旦退出该函数,您对函数内部变量

的任何更改都不会保留。

如果您需要设置该值并将其保存在退出

你可以将它作为指针传递!

得到一本C-book fassst :)


- Ravi


Yes some_int will be considered local and its better if it is initializ\
ed externally. Further, any changes you make to that variable
inside the function doesnt hold once you exit out of that function.
If you need to manupalate the value and have it saved upon exit
you can pass it as a pointer !
Get a C-book fassst :)

- Ravi


Rob Somers写道:
Rob Somers wrote:
说我有以下代码:


好​​的: 我有以下代码。

void foo(int some_int);
....
int x = 5;
foo(x) ;
....

void foo(int some_int)
{/> printf("%d \ n",some_int);
}'/>
将'some_int'视为局部变量,(恰好在外部初始化)?如果不是,它会被视为什么?
Say I have the following code:
All right: "I have the following code."
void foo(int some_int);
....
int x = 5;
foo(x);
....

void foo(int some_int)
{
printf("%d\n", some_int);
}

Would ''some_int'' be considered a local variable, (which happens to be
initialised externally)? If not, what would it be considered as?




标识符some_int出现在两个上下文中:一次

在声明中foo()和一次定义。在

声明它真的只是评论:

的名字永远不会被使用,也可能被省略或

换成另一个。您可以将声明

写成`void foo(int);''或作为`void foo(int huge_array_of_float);''

具有完全相同的效果。


在定义中,`some_int''是函数'

形式参数的名称。该参数的行为非常类似于本地

变量,该变量已使用调用者提供的

对应参数表达式的值进行初始化。

参数存在并且在foo()开始执行时具有其值,

并且它继续存在直到foo()返回或以其他方式停止

来执行。就像一个局部变量一样,它保留了它的价值,直到和b
,除非你为它指定一个新值,然后保留该值。

从技术上讲,它不是本地的变量但是一个参数 -

但是这是一个重言式,因为从技术上来说,没有像本地变量这样的东西。在语言中。


-

Eric Sosman
es ***** @ acm-dot-org.inva 盖子



The identifier `some_int'' appears in two contexts: once
in the declaration of foo() and once in its definition. In
the declaration it''s really just commentary: A name that
never gets used and could just as well have been omitted or
replaced with another. You could have written the declaration
as `void foo(int);'' or as `void foo(int huge_array_of_float);''
with exactly the same effect.

In the definition, `some_int'' is the name of the function''s
formal parameter. The parameter behaves very much like a local
variable that has been initialized with the value of the
corresponding argument expression provided by the caller. The
parameter exists and has its value when foo() starts to execute,
and it continues to exist until foo() returns or otherwise ceases
to execute. Like a local variable it retains its value until and
unless you assign a new one to it, and then retains that value.
Technically, though, it is not a local variable but a parameter --
but this is a tautology, because technically there is no such
thing as a "local variable" in the languge.

--
Eric Sosman
es*****@acm-dot-org.invalid


Rob Somers写道:
Rob Somers wrote:
说我有以下代码:

void foo(int some_int);
....
int x = 5;
foo( x);
....

void foo(int some_int)
{/> printf("%d \ n",some_int);

将'some_int'视为局部变量(恰好是外部初始化的)?如果没有,会被视为什么?
Say I have the following code:

void foo(int some_int);
....
int x = 5;
foo(x);
....

void foo(int some_int)
{
printf("%d\n", some_int);
}

Would ''some_int'' be considered a local variable, (which happens to be
initialised externally)? If not, what would it be considered as?




标准谈及存储持续时间和标识范围。


这里,some_int具有自动持续时间和函数原型范围。


当调用foo(x)时,some_int被赋值为x,如:some_int = x;


-

彼得



The standards talk in terms of storage duration and identifier scope.

Here, some_int has automatic duration and function prototype scope.

When foo(x) is called, some_int is assigned x, as in: some_int = x;

--
Peter


这篇关于功能参数的描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆