29 Jun

1. What are the three general characteristics of subprograms?
• Each subprogram has a single entry point.
• The calling program unit is suspended during the execution of the called
subprogram, which implies that there is only one subprogram in execution
at any given time.
• Control always returns to the caller when the subprogram execution

2. What does it mean for a subprogram to be active?
A subprogram is said to be active if, after having been
called, it has begun execution but has not yet completed that execution.

3. What is given in the header of a subprogram?
First, it specifies that the following syntactic unit is a subprogram
definition of some particular kind.1 In languages that have more than one
kind of subprogram, the kind of the subprogram is usually specified with a
special word. Second, if the subprogram is not anonymous, the header provides
a name for the subprogram. Third, it may optionally specify a list of

5. What languages allow a variable number of parameters?

7. What is a parameter profile? What is a subprogram protocol?
The parameter profile of a subprogram contains the number, order, and
types of its formal parameters. The protocol of a subprogram is its parameter
profile plus, if it is a function, its return type.

8. What are formal parameters? What are actual parameters?

formal parameter — the identifier used in a method to stand for the value that is passed into the method by a caller.
actual parameter — the actual value that is passed into the method by a caller.

9. What are the advantages and disadvantages of keyword parameters?
the advantage of keyword parameter is that they can appear in any order in the actual
parameter list
the disadvantage to keyword parameters is that the usr of the subprogram must know the
names of formal parameters

10. What are the differences between a function and a procedure?
function return a value
procedure doesn’t return a value

12. What are the advantages and disadvantages of dynamic local variables?
advantages : flexibility, memory efficient.
disadvantages : cost more time, indirect access, not history sensitive.

5. Consider the following program written in C syntax:
void swap(int a, int b) {
int temp;
temp = a;
a = b;
b = temp;
void main() {
int value = 2, list[5] = {1, 3, 5, 7, 9};
swap(value, list[0]); value=2 ,list={3,1,5,7,9}
swap(list[0], list[1]);
swap(value, list[value]);
For each of the following parameter-passing methods, what are all of the
values of the variables value and list after each of the three calls to
a. Passed by value
value = 2, list={1,3,5,7,9}
b. Passed by reference
value=2 ,list={3,1,5,7,9}
c. Passed by value-result
value = 2, list={3,1,5,7,9}

6. Present one argument against providing both static and dynamic local
variables in subprograms.
it’s resulting a less time efficient result.

7. Consider the following program written in C syntax:
void fun (int first, int second) {
first += first;
second += second;
void main() {
int list[2] = {1, 3};
fun(list[0], list[1]);

For each of the following parameter-passing methods, what are the values
of the list array after execution?
a. Passed by value
b. Passed by reference
c. Passed by value-result

8. Argue against the C design of providing only function subprograms.
it’s actually okay, as a void function can serve as a procedure.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: