Chapter 9 Flashcards
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