Chapter 5 Functions Flashcards

1
Q

How to typecast some data into a string

A

simply put “….”

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

Proper use of functions

A

Notice repetitive bits

- Take them out and put them in a separate function

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

Argument

A

data passed into a function

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

Parameters

A

the labels given to each datum passed into the function. The parameter is initialised into a local variable with the value of the corresponding argument.

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

Local variable

A

Declared within, only exist during execution of, and can only be accessed within, a particular function and its execution.

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

Frame

A

A function can have many variables and all of them are stored in the frame for that function. Think of it as a blackboard which you can write on during the execution of a function. Once the function is done, the blackboard is thrown away.

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

Stack

A

System of organising frames – frames added when a function is called and put ‘on top of the stack’ and the frame is destroyed as the function finishes executing. The first into the stack is the last out of the stack. Visualise this as a stack of blackboards with subsidiary tasks getting their own frame on top of the stack as they are initialised, and so forth…

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

Return

A

A function may return a value upon completion of execution, but may be a (void) one where it simply has a side effect when called and does not return any values. The type of the returned data can be elicited from the type preceding the function name occurring at the start of its definition.
IMPORTANT NOTE: execution of a function stops when it returns a value….

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

Global variables

A

Can be accessed from any function at any time

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

Static variable

A

Can be accessed by different functions at any time but ONLY WITHIN THE FILE IN WHICH IT WAS DECLARED. put a static in front of the definition e.g.

static float variableXYZ;

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

How to make a literal string

A

Surround the text with quotation marks “…….”

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

Token

A

%s - swaps with a string
%d - swaps with integer
%f - swaps with floating point number

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

Explicit new line character for a format string

A

” \n” tells program to start a new line.

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

Cast operator

A

(float) 3

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

Arithmetic shorthand operators

A
x++ increment
x-- decrement
x += 5, x+5 
x *= 
x /= 
x %= 
"Perform the operation and then reassign x equal to that value"...
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Standard library header

A

include

17
Q

Decimal place modification to tokens

A

e.g. %.3f to 3dp

18
Q

Maths library

A

include

Enter terminal and input:
man math