PREDEFINED AND USER-DEFINED FUNCTIONS Flashcards

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
Q

syntax for a formal parameter list

A

(dataType identifier, dataType identifier, …)

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

syntax for calling a value-returning function

A

functionName(actual parameters);

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

syntax for actual parameter list

A

(expression or variable, expression or variable, …);

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

TRUE OR FALSE: a formal parameter list can be empty (no passing parameter)

A

true

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

once a value-returning function computes the value, the function returns the value via the ______ statement

A

return

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

return statement syntax

A

return expression;

31
Q

TRUE OR FALSE: in c++, return is not a reserved word

32
Q

when a return statement executes…

A
  • function immediately terminates
  • control goes back to the caller
33
Q

what happens when a return statement executes in the function main

A

the program terminates

34
Q

function heading without the body of the function

A

function prototype

35
Q

syntax of a function prototype

A

functionType functionName (parameter list);

36
Q

TRUE OR FALSE: in a function prototype, it is necessary to specify the variable name in the parameter list

37
Q

TRUE OR FALSE: in a function prototype, the data type of each parameter must be specified

38
Q

execution always begins at……

A

the first statement in the function main

39
Q

when are other functions outside main executed

A

only when they are called

40
Q

these appear before any function definition because the compiler translates these first

A

function prototypes

41
Q

this results in transfer of control to the first statement in the body of the called function

A

a function call

42
Q

after the last statement of a function is executed, control is….

A

passed back to the point immediately following the function call

43
Q

after executing the function, the returned value…..

A

replaces the function call statement

44
Q

TRUE OR FALSE: user-defined void functions can only be placed before the function main

45
Q

these have similar structures with value-returning functions; both have a heading part and a statement part

A

void functions

46
Q

if a user-defined void function is placed after main, …

A

the function prototype must be placed before the function main

47
Q

this does not have a return type

A

void function

48
Q

in void functions, this is typically used to exit the function early

A

return statement without any value

49
Q

in void functions, these are optional

A

formal parameters

50
Q

a call to a void function is a __________

A

stand-alone statement

51
Q

void function definition syntax

A

void functionName(formal parameters)
{
statements
}

52
Q

void function call syntax

A

functionName(actual parameters);

53
Q

in void functions, it is a formal parameter that receives a copy of the content of the corresponding actual parameter

A

value parameter

54
Q

in void functions, it is a formal parameter that receives the location (memory address) of the corresponding actual parameter

A

reference parameter

55
Q

in void functions, this happens when a formal parameter is a value parameter

A

the value of the corresponding actual parameter is copied into it

56
Q

during program execution, this manipulates the data stored in its own memory space

A

value parameter

57
Q

in the case of a reference parameter, …

A

the address of the actual parameter passes to the formal parameter

58
Q

this is the content of a formal parameter

59
Q

TRUE OR FALSE: during execution, changes made by the formal parameter permanently change the value of the actual parameter

60
Q

stream variables (such as ifstream) should be _______________ to a function

A

passed by reference

61
Q

TRUE OR FALSE: you cannot use reference parameters in a value-returning function

62
Q

by definition, a value-returning function returns _________ value

63
Q

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

A

void function

64
Q

this refers to where in the program an identifier is accessible

A

scope of an identifier

65
Q

these are identifiers declared within a function (or block)

A

local identifier

66
Q

these are identifiers declared outside of every function definition

A

global identifier

67
Q

TRUE OR FALSE: c++ allows nested functions

68
Q

in a c++ program, several functions can have the same name, this is called ____________________ or ____________________

A

function overloading, overloading a function name

68
Q

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

A

different formal parameter list

69
Q

creating several functions with the same name

A

function overloading

70
Q

this consists of the function name and its formal parameter list

A

the signature of a function

71
Q

two functions have different signatures if …?

A

either different names or different formal parameter lists