P&A - Functions in C Flashcards
Functional decomposition
Functions break a larger program into smaller parts
How would you define a function?
return type function_name(parameter declarations) { variable declarations Statements }
Entry point
Where the program starts running
In C, it’s the main() function
Function parameters
Allow us to pass a value from one function to another
e.g. numSwap(int num1, int num2)
Function parameters are automatic variables and are initialised with a copy of the value passed (pass by value)
Pass by value
Function parameters are automatic variables and are initialised with a copy of the value passed (pass by value)
What is the lifetime and scope of a function’s variables?
As the variables in a function are automatic, the scope is local to the function, and have a lifetime of only when the function is running
How many values can a function return at once?
One (single value)
void keyword
Used to declare that there is no return value, or can also use to declare no parameters
printf() function library?
what are the conversion characters to print the following:
strings unsigned decimal float double int
string - %s unsigned decimal - %u float - %f double - %lf int - %d
escape characters
\n - new line \t - tab \b - backspace \" - double quote \\ - backslash