7- predefined functions (library functions) Flashcards

1
Q

Function

A

named group of statements carrying out a particular task that accepts values and computes the result

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

Function name

A

identifier distinguishing the function from others
example – square root function: sqrt

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

argument

A

the value accepted by the function to use in computation

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

return value

A

value computed by the function

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

function call (function invocation)

A

executing function code from elsewhere in program
syntax: expression consisting of function name followed by arguments in parentheses
result = sqrt(9.0);
semantics: argument is evaluated, function is executed, return value replaces function invocation
invocation forms
in expression – return value replaces invocation in expression evaluation
result = sqrt(9.0) – myVar5;
standalone – return value is ignored
srand(55);
argument variants
function may have more than one argument
result = pow(myVar, 55);
an argument is an (arbitrary) expression
result = sqrt(myVar
2 + 9.0);
nested function call: use of one function call as argument to another
result = sqrt(abs(myVar));

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

casting

A

explicit type conversion

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

coercion

A

implicit type conversion

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

Random number generation

A

(pseudo) random number generation pre-defined functions are used to create events unpredictable by user (e.g. events in games)
need to include <cstdlib>
generates a series of numbers, numbers within single series are (pseudo) random</cstdlib>

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

srand(seed)

A

initializes random number generator, needs to be invoked once in the program, no return value

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

seed

A

integer, selects the (pseudo) random series

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

rand()

A

returns a new integer random number in the series, can be used multiple times in program, no argument

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

time(nullptr)

A

returns number of seconds since 01/01/1970, good for initializing unique series, needs <ctime>
nullptr is there for historical reasons</ctime>

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

srand(1);

A

repeats series every time you run your program – good for debugging

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

srand(time(nullptr));

A

selects unpredictable series every time you run your program – good for final compilation

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