Functions Flashcards

1
Q

A function is

A

is a named list of statements.

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

A function definition consists of the new function’s name and a

A

block of statements. Ex: double CalcPizzaArea() { /* block of statements */ }

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

A function call is

A

an invocation of a function’s name, causing the function’s statements to execute.

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

The function’s name can be any valid identifier. A block

A

is a list of statements surrounded by braces.

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

A function may return one value using a

A

return statement. Below, the ComputeSquare() function is defined to have a return type of int; thus, the function’s return statement must have an expression that evaluates to an int.

return numToSquare * numToSquare;

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

A parameter is a

A

function input specified in a function definition. Ex: A pizza area function might have diameter as an input.

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

An argument is a

A

value provided to a function’s parameter during a function call. Ex: A pizza area function might be called as CalcPizzaArea(12.0) or as CalcPizzaArea(16.0).

Write a statement that calls a function named CalcCalories, passing the value 3 as an argument.

CalcCalories(3);

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

A parameter, like a variable declaration,

A

cannot be an expression.

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

A function definition may have multiple parameters, separated by commas. Parameters are assigned with argument values by position: First parameter with first argument, second with second, etc.

A function definition with no parameters must still have

A

the parentheses, as in: int DoSomething() { … }. The call must include parentheses, with no argument, as in: DoSomething().

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

Which correctly passes two integer arguments for the function call:
CalcVal(…)?

A

(99, 45 + 5)

Each argument evaluates to an integer.

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

The number of parameters and arguments must

A

match

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

A function declaration specifies the function’s

A

return type, name, and parameters, ending with a semicolon where the opening brace would have gone. A function declaration is also known as a function prototype.

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

Sometimes a function’s last parameter (or last few) should be optional. A function call could then omit the last argument, and instead the program would use a default value for that parameter. A function can have a

A

default parameter value for the last parameter(s), meaning a call can optionally omit a corresponding argument.

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

For global scope should only ( ) should be declared

A

constants

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

It is not considered good programming to declare global variables.

A

True

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

A function can have no parameters, one parameter, or many parameters and can return ________ value(s).

A

only one

17
Q

The value in this type of variable persists between function calls.

A

static

18
Q

The value in a ________ variable persists between function calls.

A

static local

19
Q

A function can only return

A

one item, not two or more

20
Q

Calling a function basically means

A

starting the execution of the instructions contained in that module.

21
Q

The int main()function consists mostly of calls to functions just like

A

a con- tractor issues commands to sub-contractors to come and do their jobs.

22
Q

Sometimes a function may need information “passed”

A

in order to perform designated tasks.

23
Q

If a function is to find the square root of a number, then it needs that num- ber passed to it by

A

the calling function.

24
Q

Parameters are the

A

components of communication between functions.

25
Q

Information is passed to or from a func- tion

A

through parameters.

26
Q

Notice the call consists

A

only of the name of the function (not the word void preceding it) followed by the set of parentheses and a semicolon.

printDescription(); // Call to the function

27
Q

The parameters in a function heading are called

A

formal parameters