Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Multiple-Choice: 1. How many formal parameters can be included in a function def

ID: 3903133 • Letter: M

Question

Multiple-Choice:

1.      How many formal parameters can be included in a function definition?

a.       zero or more

b.      zero

c.       one or more

d.      exactly one

2.      Given the function prototype below:

void foo(double x, int y);

Which statement correctly calls the function foo?

a.       num = foo(12.5, 10);

b.      num = foo(x, y);

c.       foo(10, 12.5);

d.      foo(12.5, 10);

Answer to the question

3.      What is the advantage of breaking your application’s code into several small functions?

Explanation / Answer

3)Answer:

Each function can handle one small, manageable task. This makes it easier to design, code,
test, and debug.

Breaking big functions up in to several smaller ones can lead to

There are a few potential benefits to breaking big functions up in to smaller functions.

It encourages code-reuse. Often in large functions you have to do more-or-less the same thing many times. By generalizing this in to a single common function, you can use that one block of code in multiple places.

Code-reuse can aid in robustness and maintainability by isolating potential bugs to one place rather than several.

It is easier to understand the semantics of the function when there are fewer lines of code and a bunch of calls to well-named functions.

If you are opposed to functions with multiple return points, breaking big functions up can help reduce them.

It helps to identify and isolate (potential) problems with subtle data dependencies that are otherwise hard to notice.

It's important to note however that you take the good with the bad with this. There are also a few potential drawbacks to breaking big functions up:

If the big function worked before, trying to modularize it may create defects.

In multithreadded applications, you might introduce deadlocks and race conditions if your synchronization policies are subtle or just plain wrong.

You might introduce a performance hit from the function calls