Chapter 5 Functions Flashcards
How to typecast some data into a string
simply put “….”
Proper use of functions
Notice repetitive bits
- Take them out and put them in a separate function
Argument
data passed into a function
Parameters
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.
Local variable
Declared within, only exist during execution of, and can only be accessed within, a particular function and its execution.
Frame
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.
Stack
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…
Return
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….
Global variables
Can be accessed from any function at any time
Static variable
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 to make a literal string
Surround the text with quotation marks “…….”
Token
%s - swaps with a string
%d - swaps with integer
%f - swaps with floating point number
Explicit new line character for a format string
” \n” tells program to start a new line.
Cast operator
(float) 3
Arithmetic shorthand operators
x++ increment x-- decrement x += 5, x+5 x *= x /= x %= "Perform the operation and then reassign x equal to that value"...