Professional Documents
Culture Documents
Pres 2
Pres 2
378179
Subroutines : introduction
In computer programming, a subroutine is a
sequence of program instructions that performs a
specific task, packaged as a unit.
This unit can then be used in programs wherever
that particular task should be performed.
Prevents code repeatetion and improves
reusability.
Subroutines in different languages
In different programming languages, a subroutine
may be called :
a procedure
a function
a routine
a method
or a subprogram
The generic term callable unit is sometimes used.
Components of a Subroutine
Body : The content of a subroutine is its body,
which is the piece of program code that is executed
when the subroutine is called or invoked.
Header : Contains name, return type and
parameter list
Subroutine : Example
public int total(int n1,int n2){ // header
int tot=n1+n2;
return tot; // return statement
}
//Invoking a subroutine :
Calling :
Int a=100;
Int b=200;
swap(a, b);
References
https://en.wikipedia.org/wiki/Subroutine
www.tutorialspoint.com