Lecture 11 Flashcards

1
Q

What is a subprogram definition?

A

It describes the interface and actions of the subprogram abstraction.

In Python, function definitions are executable; in other languages, they are non-executable.

In Ruby, function definitions can appear either in or outside class definitions.

In Lua, all functions are anonymous.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a subprogram call and header?

A

A subprogram call is an explicit request for the subprogram to be executed. A subprogram header is the first part of the definition, including the name, kind of subprogram, and formal parameters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the parameter profile and protocol of a subprogram?

A

The parameter profile (signature) is the number, order, and types of parameters. The protocol includes the parameter profile and the return type if it is a function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are function declarations in C and C++ called?

A

They are often called prototypes. A subprogram declaration provides the protocol but not the body of the subprogram.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are formal and actual parameters?

A

A formal parameter is a dummy variable listed in the subprogram header and used in the subprogram.
An actual parameter represents a value or address used in the subprogram call statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the fundamental characteristics of subprograms?

A

Each subprogram has a single entry point. The calling program is suspended during the execution of the called subprogram, and control always returns to the caller after the subprogram’s execution terminates.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are positional and keyword parameter bindings?

A

Positional binding binds actual parameters to formal parameters by position. Keyword binding specifies the formal parameter name with the actual parameter, allowing parameters to appear in any order.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How are default parameter values handled in various languages?

A

Languages like C++, Python, Ruby, PHP allow formal parameters to have default values. In C++, default parameters must appear last due to positional association.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do different languages handle variable numbers of parameters?

A

C# uses an array preceded by params. Ruby uses a hash literal with an asterisk. Python uses a list of values with an asterisk. Lua uses three periods as a formal parameter.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the differences between procedures and functions?

A

Procedures are collections of statements defining parameterized computations. Functions resemble procedures but are semantically modeled on mathematical functions and expected to produce no side effects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the design issues for subprograms?

A

Issues include local variables’ static or dynamic nature, subprogram definitions in other subprograms, parameter passing methods, parameter type checking, functional side effects, return types and values, subprogram overloading, and generic subprograms.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the characteristics of stack-dynamic and static local variables?

A

Stack-dynamic local variables support recursion and share storage among subprograms but have allocation/de-allocation time and indirect addressing issues.

Static local variables have opposite advantages and disadvantages.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What do activation records contain?

A

Activation records contain local variables, parameters, return address, and control information necessary for procedure calls and returns.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does procedure activation represent and what is an activation tree?

A

Procedure activation represents the actions when a caller invokes a callee, including the transfer of actuals into formals, allocation of memory for local variables, and identification of the control return point.

An activation tree graphically represents activations over time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the design issues for functions?

A

Issues include allowing side effects, types of return values, return value restrictions, returning functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
A