October 2016
Beginner
520 pages
10h 19m
English
So what exactly are C++ functions? A function is a collection of variables, expressions, and control flow statements (loops and branches). In fact, any of the code we have learnt about in the book so far can be used in a function. The first part of a function that we write is called the signature. Here is an example function signature:
public void bombPlayer(int power, int direction)
If you add an opening and closing pair of curly braces {…} with some code that the function actually performs then we have a complete function, a definition:
void shootLazers(int power, int direction)
{
// ZAPP!
}
We could then use our new function in another part of our code, as follows:
// Attack the player bombPlayer(50, 180) // Run ...
Read now
Unlock full access