It is possible (and quite normal) to have multiple functions in your C code! By splitting up your code into functions, debugging can become much easier, your code will be more readable, it will be easier for you to remember what you had in mind, ... but more on that later. For now, let’s take a look at an example that involves multiple functions:
If you cannot see this codecast, please click here.
Check Your UnderstandingCheck Your Understanding
1.
What are some of the advantages of using functions (choose all that apply)?
easy modification of code
Correct
abstraction
Correct
ability to reuse code without having to copy and paste
Correct
there are no advantages
Not quite. Try again!
2.
Given the following function definition, which is the correct function call, given that a variable a of type int has been declared?
int myaddition(int x, int y)
{
return(x+y);
}
Feel free to use the window below to try out some code. Be sure to work the correct answer out "by hand" first before verifying your answer using the code window.