For faster navigation, this Iframe is preloading the Wikiwand page for 子程序.

子程序

“子程序”的各地常用名称
中国大陆子程序、子例程
台湾子程式、副程式、次程式、次常式

电脑科学中,子程序(德语:unterprogramm,英语:subroutine, subprogram, callable unit),是一个大型程序中的某部分代码,由一个或多个语句块组成。它负责完成某项特定任务,而且相较于其他代码,具备相对的独立性。

一般会有输入参数并有返回值,提供对过程的封装和细节的隐藏。这些代码通常被集成为软件库

函数在面向过程的语言中已经出现。是结构struct)和class)的前身。本身就是对具有相关性语句的归类和对某过程的抽象。

分类

子程序是一个概括性的术语,子程序是所有高阶程序所称。它经常被使用在汇编语言层级上。子程序的主体(body)是一个代码区块,当它被调用时就会进入执行。

函数

“函数”的各地常用名称
中国大陆函数
台湾函式、函数
港澳函数

函数function)是一种子程序,利用函数名称,可以接收回传值。例如:

c = max(a,b);

过程

“过程”的各地常用名称
中国大陆过程
台湾程序
港澳程式

过程procedure)是一种子程序,它能够接受不同的引数,来执行某些特别的动作。例如:

printf("Hello World\n");

函数与过程在某些编程语言中是被分开的,但是在C语言中,所有过程都是函数,这两者被认为是相同的。这有可能造成一些副作用,特别是在回传值是void类型时。

方法

面向对象编程语言中,物件中的子程序,被称为方法method)。

{{bottomLinkPreText}} {{bottomLinkText}}
子程序
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?