Chapter 9 Flashcards
What are the 2 fundamental abstraction facilities?
Process abstraction
Data abstraction
Fundamentals of the subprograms
Single entry point.
Calling program is suspended during subprogram execution
Control returns to caller after execution of sub program
What is a subprogram definition?
(the entire function) Defines interface(how to use) + actions(What is does) of a subprogram
What is a subprogram header?
1st part of the subprogram definition ( name, type, parameters
Example of a subprogram header:
int doSomething(int first){…}
Formal vs actual parameters:
Formal = “dummy” (int first)
Actual = (12)
What is a parameter profile/signature?
Parameters + types of the function
(length: int, width : int, height : int)
What is a protocol?
Parameter profile + return type
int calc(x: int, y: int);
What is a subprogram declaration?
The entire function
Prototype function example:
void foo(int,float);
What is a positional parameter?
Bind actual to formal parameters by position
What is the advantage of positional parameters?
Safe and effective
Disadvantage of positional parameters?
Hard to read + if you switch 2 numbers, the function will still run perfectly
What is keyword parameters?
Bind to the names of formal parameters
Example of keyword parameters:
add(first = 10, second = 12, third = 3)
Advantage of keyword parameters?
Any order
Avoid parameter correspondence errors
DisAdvantage of keyword parameters?
Writeability
What are default parameters?
When you assign a value to the parameter in the declaration. If no value is passed in for that parameter then it get assigned the default value
Why must default parameters be last?
How else would you know which parameter is which/
How many parameters are there in variable number parameter?
1+
How are variable number of parameters processed?
Like a list
Difference between functions and procedures?
Procedures give results by modifying.
Functions give results by returning
Do procedures have return values?
No
Advantage of stack-dynamic local variables:
recursion + flexibility