递归中的分段错误 [英] segmentation fault in recursion

查看:65
本文介绍了递归中的分段错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include< stdio.h>


int main()

{

int i;

for(i = 1; i< = 10; i ++)

main();

printf(" C is urs ..") ;

返回0;

}


为什么显示错误分段错误?

#include <stdio.h>

int main()
{
int i;
for(i=1;i<=10;i++)
main();
printf("C is urs..");
return 0;
}

Why it shows error segmentation fault ??

推荐答案

1月15日晚上10点10分,asit< lipu ... @ gmail.comwrote:
On Jan 15, 10:09 pm, asit <lipu...@gmail.comwrote:

#包括< stdio.h>


int main()

{

int i;

for(i = 1; i< = 10; i ++)

main();

printf(" C is urs ..");

返回0;


}


为什么它显示错误分段错误?
#include <stdio.h>

int main()
{
int i;
for(i=1;i<=10;i++)
main();
printf("C is urs..");
return 0;

}

Why it shows error segmentation fault ??



因为你是一个巨魔。

就C而言,这是完全有效的代码。

也许是系统限制。 C(或clc)与此无关。

Because you''re a troll.
As far as C is concerned, that is perfectly valid code.
perhaps a system limitation. C (or c.l.c) has nothing to do with that.


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

1月15日晚上10点10分,asit< lipu ... @ gmail.comwrote :
On Jan 15, 10:09 pm, asit <lipu...@gmail.comwrote:

> #include< stdio.h>

int main()
{
int i ;
for(i = 1; i< = 10; i ++)
main();
printf(" C is urs ..");
返回0;

}

为什么它显示错误分段错误?
>#include <stdio.h>

int main()
{
int i;
for(i=1;i<=10;i++)
main();
printf("C is urs..");
return 0;

}

Why it shows error segmentation fault ??



因为你是巨魔。


Because you''re a troll.



你可能是对的。

You may be right about that.


就C来说,这是完全有效的代码。

也许是一个系统限制。 C(或c.l.c)与此无关。
As far as C is concerned, that is perfectly valid code.
perhaps a system limitation. C (or c.l.c) has nothing to do with that.



代码是有效的因为它表示一个计算。

不幸的是,计算不会在有限的时间内完成,有限的机器也不会很容易保持

跟踪其中间状态。不方便的词

有限事实上它确实表达了一个系统限制,但它的限制只能很难被删除

并且需要付出一些代价。

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


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

1月15日晚上10点10分,asit< lipu ... @ gmail.comwrote:
On Jan 15, 10:09 pm, asit <lipu...@gmail.comwrote:

> #include< stdio.h>

int main()
{
int i;
for(i = 1 ; i< = 10; i ++)
main();
printf(" C is urs ..");
返回0;

}

为什么它会显示错误分段错误?
>#include <stdio.h>

int main()
{
int i;
for(i=1;i<=10;i++)
main();
printf("C is urs..");
return 0;

}

Why it shows error segmentation fault ??



因为你是一个巨魔。

就C来说,这是完全有效的代码。

也许是系统限制。 C(或c.l.c)与此无关。


Because you''re a troll.
As far as C is concerned, that is perfectly valid code.
perhaps a system limitation. C (or c.l.c) has nothing to do with that.



OP可能是也可能不是巨魔,但我不会将代码称为

完全有效。这是一个无限的递归循环,程序

将尝试消耗无限的资源,除非编译器管理

来优化递归。 main()自称10次。这10个实例中的每个

将再次调用main 10次。等等。


-

Keith Thompson(The_Other_Keith)< ks *** @ mib.org>

诺基亚

我们必须做点什么。这是事情。因此,我们必须这样做。

- Antony Jay和Jonathan Lynn,是部长

The OP may or may not be a troll, but I wouldn''t call the code
"perfectly valid". It''s an infinite recursive loop, and the program
will attempt to consume infinite resources unless the compiler manages
to optimize away the recursion. main() calls itself 10 times. Each
of these 10 instances will again call main 10 times. And so on.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"


这篇关于递归中的分段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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