This preview shows page 1. Sign up to view the full content.
Unformatted text preview: s enclosed within a pair of parentheses. If you do
not need or want to pass any arguments to the subprogram, the empty parentheses
are still required normally to distinguish the statement as a subprogram call. For
example, a statement to call the subprogram which calculates the square root of a
number may be
a = sqrt (b);
Different programming languages may have different syntax for writing the call
statement for calling a subprogram.
Set of instructions that perform the intended task
While executing a program that has one or more subprogram call statements, when
the computer encounters a subprogram call statement, the control flow jumps to
wherever the subprogram's code is, executes the statements in the subprogram
body, then returns to that statement of the calling program which is immediately
after the call statement. The flow of control in case of a subprogram call is
illustrated in Figure 12.25. Note that the subprogram itself need never be written
again, nor need it appear more than once in a program, no matter how often its
services may be required.
Subprograms may be intrinsic or programmer-written. Intrinsic subprograms
(commonly referred to as built-in-functions) are those provided with the language
so that the programmer need only call them in a program to have them
automatically invoked. There are many functionalities such as those for finding
square roots, sines, cosines, logarithms, etc., which are used over and over again
by many programmers in their programs. Such functionalities are usually supplied
along with a programming language in the form of built-in-functions. On the other
hand, programmer-written subprograms are written and used as and when they are
Subprograms can also return a value to the calling program. This makes it
convenient to use a subprogram to set the value of a variable. For example, in case
of our subprogram to calculate the square root of a number, you supply the
number as its parameter,, and the, subprogram calculates...
View Full Document
This document was uploaded on 04/07/2014.
- Spring '14