9 + 10. Functions Flashcards

1
Q

function declaration

A
  • declare functions before use
  • incl all info needed to use function
  • provide comment w/ each function declaration
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

info needed to use function

A
function data type
function name
parameters with their data types
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

function definition

A
  • consists of declaration + function body

- body: computes function value + returns a value unless it is a void function

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

what functions can return

A

doubles, ints, chars, strings, booleans, etc

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

boolean function

A

useful for abstracting complex abstractions

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

parameters

A

in the declaration, the info inside () are the formal parameters of the function

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

arguments

A

when calling a function, the values put into the () are the arguments passsed to the function

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

zero parameters

A
eg. int f();
double g();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

when to use a function

A
  • when task is easy to identify but hard to implement code

- whenever you have to write same code or v. similar code a second time (when code can be repeated)

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

pass by reference (call-by-reference)

A

use of &, changes the argument

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

pass by value (call-by-value)

A

no use of &, does not change the argument

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

void functions

A

functions that dont return anything

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

void functions syntax

A

void function_name (parameters);

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

need for call-by-reference parameters

A

for when we want a function to:

  • read in a bunch of data eg. read payroll details
  • return multiple values eg. day, month, year
  • change 2 values in tandem eg. simplify fraction
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

call-by-reference parameters

A
  • can update storage places
  • instead of passing value into function, pass a reference to a place where value is stored
  • use ampersand (&)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

using ampersands

A
  • only use if you want function to change value of a variable in main
  • dont use if function only needs the value of parameter