Chapter 9 Flashcards
(43 cards)
What are the 2 types of abstraction?
Process abstraction
Data abstraction
What are the fundamentals of subprograms?
Single point of entry
If subprogram is called, calling program is suspended
After execution control is returned to the caller
Basic definition for subprograms
Defines interface and action
Interface specifies how the subprogram is used + name + parameters +…
Actions: Specify hat it does (body)
What is a subprogram header?
The 1st part of the subprogram definition.
Name kind parameters
What is the difference between formal parameters and actual parameters?
Formal: Dummy variable in header. Used in subprogram
Actual: Values being passed in
What is a parameter profile(signature)?
Number, order and types of parameters
What is a protocol?
Parameter profile with function return types
What is a subprogram declaration?
Provides subprogram protocol, but not its body (prototype (void doSomething(int);)
What is the Parameter correspondence?
for a subprogram call we must match actual parameters to formal parameters.
What is the advantage of Positional parameters?
1st parameter = 1st parameter etc…
It is safe and effective
What is the disadvantage of Positional parameters?
reduced readability + error prone
What is the advantage + disadv of Keyword parameters?
Adv: Avoid corespondence errors. can appear in any order (improved readability)
Dis: Memorize param names
Can formal parameters have default values?
Yes
How are variable number of parameters processed?
Like a list
What are the 2 categories of subprograms?
Procedures (collections of statements that define parameterized computations)
Functions (resemble procedures but semantically modeled on mathematical functions)
How does Procedures and functions differ?
Procedures: produce result by modifying
Functions: produce results by returning a value
What is the adv and disadv of stack-dynamic variables?
adv: recursion + shared among subprograms
dis: time for allocation, initialization
What is the advantage of static local variables?
Opposite of stack-dynamic local variables
What are the 3 modes for parameters?
In mode formal parameter: received data from an actual parameter
Out mode: Sends data to an actual parameter
Inout mode: Both
What are the 2 ways data transfer can take place?
Physical copy of a value
Transmit access path to value
What are the 5 implementation models for parameter passing?
pass-by-value
pass by result
pass by value result
pass by reference
pass by name
What mode is pass by value?
In mode
How does pass by value work?
The value of the actual parameter is used in formal parameter
Normally implemented by copying
can be done by transmitting an access path
What mode is pass by result and how does it work?
Out mode
Value of formal parameter is used to change corresponding actual parameter