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?