4 - Parameters and Overloading Flashcards

1
Q

There are two basic kinds of parameters. They are …

A
  1. Call-by-value parameters

2. Call-by-reference parameters

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

What is a call-by-value parameter?

A

Call-by-value parameters take only the value of the argument that is plugged in.

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

What is a call-by-reference parameter?

A

With a call-by-reference parameter, the argument is a variable and the variable itself is plugged in; therefore, the variable’s value can be changed by the function invocation. A call-by-value parameter is indicated by using the ampersand &.

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

Can you mix call-by-reference and call-by-value parameters?

A
yes!
void goodStuff (int& par1, int par2, double& part3);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

When calling a function with call-by-reference parameters, what is actually given to the function?

A

A list of the memory locations associated with each parameter name.

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

What is overloading?

A

Giving two (or more) function definitions for the same function name.

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

How does the compiler know which overloaded function to use?

A

When there is a function call, the compiler uses the function definition whose number of formal parameters and types of formal parameters match the arguments in the function call.

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

Can you overload a function name by giving two definitions that differ only in the type of value returned?

A

No.

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

Can you overload based on call-by-value versus call-by-reference parameter differences?

A

No.

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

What is a function’s signature?

A

A function’s signature is the function name with the sequence of types in the parameter list, not including the const keyword and not including the ampersand, &.

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

What are the rules the compiler uses for resolving which of multiple overloaded function definitions it should use?

A
  1. Exact match.

2. Matching using automatic type conversion.

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

What is a default argument?

A

You can specify a default argument for one or more call-by-value parameters in a function. If the corresponding argument is omitted, the it is replaced by the default argument.

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

What is the syntax for default arguments?

A

void showVolume (int length, int width = 1, int height = 1);

The values are given in the function declaration, and not in the function definition.

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

Where must the default arguments be positioned?

A

They must be in the rightmost positions. If you have more than one default argument, then when the function is involved, you must omit arguments starting from the right.

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

What is the assert macro?

A

The assert macro is used like a void canton that takes one call-by-value parameter of type bool. When the assert macro is invoked, its assertion argument is evaluated. If it evaluates to true, nothing happens. If it evaluates to false, then the program ends and an error message is issued.

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

The assert macro is defined in which library?

A

include

cassert.

17
Q

An alternative to manually removing all assert macros from your code is …

A
Turning them off using
#define NDEBUG before your assert inclusion.
18
Q

What is a driver program?

A

A driver program is a program that is written to test the functions of your project. They should allow you to give a range of preconditions, and then see yourself if the postconditions are as expected.

19
Q

It is sometimes impossible or inconvenient to test a function without using some other function that has not yet been implemented. What can you do?

A

Write a stub. A stub is a simplified function, that will not necessarily perform the correct calculation, but will deliver values that can suffice for testing.