PREDEFINED AND USER-DEFINED FUNCTIONS Flashcards

(73 cards)

1
Q

these are like building blocks

A

functions

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

they allow complicated programs to be divided into manageable piecesq

A

functions

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

4 advantages of functions

A
  • a programmer can focus on just that part of the program and construct it, debug it, and perfect it
  • different people can work on different functions simultaneously
  • can be reused (even in different programs)
  • enhance program readability
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

functions are also called as these

A

modules

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

functions are like _________________

A

miniature programs

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

these can be put together to form a larger program

A

functions

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

in algebra, a function is defined as a rule or correspondence between values, called the function’s __________

A

arguments

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

predefined functions are organized into separate ______________

A

libraries

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

i/o functions are in the _________ header, whereas math functions are in the __________ header

A

iostream, cmath

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

these functions have a return type

A

value-returning functions

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

they return a value of a specific data type using the return statement

A

value-returning functions

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

value-returning functions return a value of a specific data type using the _______ statement

A

return

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

these functions do not have a return type; they do not use a return statement to return a value

A

void functions

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

to use value-returning functions, you must ________________________________

A

include the appropriate header file in your program using the include statement

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

to use value -returning functions, you must know the following items:

A
  • name of the function
  • number of parameters, if any
  • data type of each parameter
  • data type of the value returned (called the type of the function)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

TRUE OR FALSE: the value returned by a value-returning function is unique

A

true

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

a value-returning function is used in an _________ or in an __________

A

assignment, output statement

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

the first 4 properties of a value-returning function

A

heading

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

what type of function is this:

A

int abs(int number);

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

variable declared in the heading of a value-returning function

A

formal parameter

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

identify the formal parameter in this example:
int abs(int num)

A

num

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

variable or expression listed in a call to a value-returning function

A

actual parameter

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

in value-returning functions, the function type can also be called as these

A

data type or return type

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

syntax for a value-returning function

A

functionType functionName (formal parameters)
{
statements
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
syntax for a formal parameter list
(dataType identifier, dataType identifier, ...)
26
syntax for calling a value-returning function
functionName(actual parameters);
27
syntax for actual parameter list
(expression or variable, expression or variable, ...);
28
TRUE OR FALSE: a formal parameter list can be empty (no passing parameter)
true
29
once a value-returning function computes the value, the function returns the value via the ______ statement
return
30
return statement syntax
return expression;
31
TRUE OR FALSE: in c++, return is not a reserved word
false
32
when a return statement executes...
- function immediately terminates - control goes back to the caller
33
what happens when a return statement executes in the function main
the program terminates
34
function heading without the body of the function
function prototype
35
syntax of a function prototype
functionType functionName (parameter list);
36
TRUE OR FALSE: in a function prototype, it is necessary to specify the variable name in the parameter list
false
37
TRUE OR FALSE: in a function prototype, the data type of each parameter must be specified
true
38
execution always begins at......
the first statement in the function main
39
when are other functions outside main executed
only when they are called
40
these appear before any function definition because the compiler translates these first
function prototypes
41
this results in transfer of control to the first statement in the body of the called function
a function call
42
after the last statement of a function is executed, control is....
passed back to the point immediately following the function call
43
after executing the function, the returned value.....
replaces the function call statement
44
TRUE OR FALSE: user-defined void functions can only be placed before the function main
false
45
these have similar structures with value-returning functions; both have a heading part and a statement part
void functions
46
if a user-defined void function is placed after main, ...
the function prototype must be placed before the function main
47
this does not have a return type
void function
48
in void functions, this is typically used to exit the function early
return statement without any value
49
in void functions, these are optional
formal parameters
50
a call to a void function is a __________
stand-alone statement
51
void function definition syntax
void functionName(formal parameters) { statements }
52
void function call syntax
functionName(actual parameters);
53
in void functions, it is a formal parameter that receives a copy of the content of the corresponding actual parameter
value parameter
54
in void functions, it is a formal parameter that receives the location (memory address) of the corresponding actual parameter
reference parameter
55
in void functions, this happens when a formal parameter is a value parameter
the value of the corresponding actual parameter is copied into it
56
during program execution, this manipulates the data stored in its own memory space
value parameter
57
in the case of a reference parameter, ...
the address of the actual parameter passes to the formal parameter
58
this is the content of a formal parameter
address
59
TRUE OR FALSE: during execution, changes made by the formal parameter permanently change the value of the actual parameter
true
60
stream variables (such as ifstream) should be _______________ to a function
passed by reference
61
TRUE OR FALSE: you cannot use reference parameters in a value-returning function
false
62
by definition, a value-returning function returns _________ value
a single
63
if a function needs to return more than one value, you should change it to a ________________ and use the appropriate reference parameters to return the values
void function
64
this refers to where in the program an identifier is accessible
scope of an identifier
65
these are identifiers declared within a function (or block)
local identifier
66
these are identifiers declared outside of every function definition
global identifier
67
TRUE OR FALSE: c++ allows nested functions
false
68
in a c++ program, several functions can have the same name, this is called ____________________ or ____________________
function overloading, overloading a function name
68
2 functions are said to have ______________________ if both functions have: - a different number of formal parameters, or - if the number of formal parameters is the same, then the data type of the formal parameters, in the order you list them, must differ in at least one position
different formal parameter list
69
creating several functions with the same name
function overloading
70
this consists of the function name and its formal parameter list
the signature of a function
71
two functions have different signatures if ...?
either different names or different formal parameter lists
72