W4: FUNCTIONS Flashcards

1
Q

W4-Q1: What does well-designed function exhibit?

A

high COHESION and low COUPLING

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

W4-Q2: What are CLOSURES?

A

_ Nested types can access variables within the scope of their host function.
_ Such types couple their logic to their nesting environment => CLOSURES

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

W4-Q3: List 2 SYNTACTIC IMPROVEMENTS.

A

_ type-inference declaration

_ trailing return type declaration

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

W4-Q4: What is a FUNCTION POINTER?

A

_ A function POINTER holds the ADDRESS of a function type

_ The address identifies the LOCATION IN MEMORY where control is transferred to start executing the function’s code.

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

W4-Q5: What is a FUNCTION OBJECT?

A

_ is an OBJECT for which the function CALL operator has been OVERLOADED.
_ Since a function object has a TYPE, we can pass it to any other function in the SAME way that we pass an object.
_ Unlike a function POINTER, a function object can store a state.
_ We use function objects to perform the SAME operation in several different parts of an application.

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

W4-Q6: What is a LAMBDA EXPRESSION?

A

_ A function OBJECT that is called only ONCE can be replaced by a LAMBDA EXPRESSION
_ A lambda expression is an ANONYMOUS function nested within the BODY of another function.
_ It represents an UNNAMED function object that can capture variables within the scope of its caller.
_ It consists of its own FUNCTION BODY and a CAPTURE-LIST that references the NON-LOCAL variables accessed by that body.
_ We call a lambda expression with its referencing environment a closure.
_ A CLOSURE, unlike a function pointer, has DIRECT access to non-local variables.

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

W4-Q7: Describe characteristic of a function type with external/ internal LINKAGE

A

_ A function type can have either external or internal linkage.
_ A function type with EXTERNAL linkage is VISIBLE outside its translation unit, while a type with INTERNAL linkage is INVISIBLE outside its translation unit.
_ The DEFAULT linkage for a function type is EXTERNAL.
=> We could specify this redundantly using the keyword extern.
_ The main() function of every application must have external linkage.
_ To specify INTERNAL linkage, we preface the function declaration with the keyword static.

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

W4-Q8: What is RECURSIVE FUNCTION?

A

_ is a function that calls itself from within its own body.
_ Recursive functions require an EXIT CONDITION that determines when the recursion terminates.
_ Once recursion terminates control begins stepping back through the function call stack to the initial caller.
_ The exit condition prevents stack overflow caused by an ever increasing set of recursive calls.

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