子程序和函数有什么区别? [英] What is the difference between a subroutine and a function?

查看:1244
本文介绍了子程序和函数有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

功能和程序之间的区别是什么?


我在网上搜索了这个问题的答案,我得到的答案是一个函数可以返回一个值,修改一个值等,但是一个子例程不能。但是我对这个解释并不满意,在我看来,这种差异应该不仅仅是一个术语问题。



所以我正在寻找一个更概念的问题答案。

解决方案

一个函数反映函数的数学定义,该函数是从一个或多个输入到一个值的映射。 > 1



子程序是任何具有确定入口点和退出点的代码块的通用术语。



但是,这些术语的确切含义会因上下文而异。



1 。显然,这不是函数的正式数学定义。

Possible Duplicate:
What is the difference between a ‘function’ and a ‘procedure’?

I searched online for an answer to this question, and the answer I got was that a function can return a value, modify a value, etc., but a subroutine cannot. But I am not satisfied with this explanation and it seems to me that the difference ought to be more than just a matter of terminology.

So I am looking for a more conceptual answer to the question.

解决方案

A function mirrors the mathematical definition of a function, which is a mapping from 1 or more inputs to a value.1

A subroutine is a general-purpose term for any chunk of code that has a definite entry point and exit point.

However, the precise meaning of these terms will vary from context to context.


1. Obviously, this is not the formal mathematical definition of a function.

这篇关于子程序和函数有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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