实际函数调用之前的序列点 [英] Sequence Point before actual function call

查看:61
本文介绍了实际函数调用之前的序列点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

见下面的代码:


void func(int x)

{

printf("%d" ,x);

}


int main()

{

int j = 0 ;

func(j ++);

返回0;

}


应该是什么输出?


C标准表示在实际的

函数调用之前有一个序列点。所以,据我说它应该是1但我在屏幕上得到了
0(零)。

See the below code:

void func(int x)
{
printf("%d",x);
}

int main()
{
int j=0;
func(j++);
return 0;
}

What should be the output?

The C Standard says that there is a sequence point before the actual
function call. So, according to me it should have been 1 but I got
0(zero) on my screen.

推荐答案



co ************* *@gmail.com 写道:


co**************@gmail.com wrote:

见下面的代码:


void func(int x)

{

printf("%d",x);

}


int main()

{

int j = 0;

func(j ++);

返回0; < br $>
}


应该输出什么?


C标准说在之前有一个序列点实际

函数调用。所以,据我说它应该是1但我在屏幕上得到了
0(零)。
See the below code:

void func(int x)
{
printf("%d",x);
}

int main()
{
int j=0;
func(j++);
return 0;
}

What should be the output?

The C Standard says that there is a sequence point before the actual
function call. So, according to me it should have been 1 but I got
0(zero) on my screen.



在增量之前调用该函数。

func(++ j);


结果应为1.(Preincrement)

问候,

-

Walter Banks

Byte Craft有限公司
http://www.bytecraft.com

The function is called before the increment.
func(++j);

The result should be 1. (Preincrement)
Regards,
--
Walter Banks
Byte Craft Limited
http://www.bytecraft.com


co ******** ******@gmail.com 写道:

见下面的代码:


void func(int x)

{

printf("%d",x);

}


int main()

{

int j = 0;

func(j ++);

返回0;

}


输出应该是什么?
See the below code:

void func(int x)
{
printf("%d",x);
}

int main()
{
int j=0;
func(j++);
return 0;
}

What should be the output?



" 0" (如果有的话,因为最后一行输出没有

换行符)。

"0" (if there is any, since the final line of output has no
newline character).


C标准说有一个在实际的

函数调用之前的序列点。所以,据我说它应该是1但我在屏幕上得到了
0(零)。
The C Standard says that there is a sequence point before the actual
function call. So, according to me it should have been 1 but I got
0(zero) on my screen.



表达式'j ++''增加了'j''的值,并且产生了

之前的'j''值增加了。截至f()之前的序列

点,`j''的值为1(增量为

),而'x''具有值0(由'j ++''产生的值)。


请记住f()与`j'完全没有关系,但是

只有其参数表达式的值存储在x中。


-
Er ********* @ sun.com


2008年10月27日星期一11: 12:37 -0700,coolguyaroundyou写道:
On Mon, 27 Oct 2008 11:12:37 -0700, coolguyaroundyou wrote:

int j = 0;

func(j ++);


C标准表示在实际的

函数调用之前有一个序列点。所以,据我说它应该是1但我在屏幕上得到了
0(零)。
int j=0;
func(j++);

The C Standard says that there is a sequence point before the actual
function call. So, according to me it should have been 1 but I got
0(zero) on my screen.



那将是func(++ j)(预增量)。你使用了一个后增量。

That would be func(++j) (pre-increment). You used a post-increment.


这篇关于实际函数调用之前的序列点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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