递归问题

编程入门 行业动态 更新时间:2024-10-23 23:33:13
本文介绍了递归问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们可以为main()使用递归调用函数吗?. 像:::: void add(); int main() { 声明..... . . . . 返回add(); }

can we call a function using recursion for main()....... like:::: void add(); int main() { statement..... . . . . return add(); }

推荐答案

没有显示任何递归迹象:要递归,它应该直接或间接引用自身: That isn''t showing any sign of recursion: to be recursive, it should directly or indirectly reference itself: int factorial(int i) { if (i > 1) { return i * factorial(i - 1); } return 1; }

函数main就是该函数,与其他任何函数一样.我非常确定您是说函数main是用于某些应用程序入口点的函数.充当入口点是唯一使它与众不同的事情. 我不会阻止在递归中使用它.如果您确实需要它,请使用它.这将是不寻常的,有人说这不是最好的编程风格,但我会说,这没什么不好的.当然,如果可以找到它的好用处. :-) 请在对问题的评论中看到我的问题.您的代码或伪代码没有任何递归迹象.您演示的只是转发声明,它与递归无关.因此,这使我不确定您是否知道这是什么.因此,以防万一: en.wikipedia/wiki/Recursion_(computer_science) [ ^ ].
—SA
The function main is just the function, like any other function. I''m pretty much sure you mean the function main is the one used for the entry point of some application. Serving as the entry point is the only thing which makes is special. I does not prevent using it in recursion. Use it if you really want it. This will be unusual, and some say this is not the best programming style, but I would say, there is nothing too bad about it. If you can find a good use of it, of course. :-) Please see my question in my comment to the question. Your code or pseudo-code does not show any signs of recursion. What you demonstrated is just forward declaration which has nothing to do with recursion. So it makes me not sure if you know what is it. So, just in case: en.wikipedia/wiki/Recursion_(computer_science)[^].
—SA

更多推荐

递归问题

本文发布于:2023-11-30 20:32:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1651393.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:递归

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!