Simply, there's 3 basic parts to a function:
1) The return type (ie: the function output)
2) The name of the function
3) The parameters (ie: the function input)
Now, functions
always have parenthesis after the name. That's what identifies them as functions. In the prototype and definition, the parameter list goes inside those parenthesis.
For example:
Here, 'void' is the return type (indicating the function does not return any output)
'func' is the function name
and 'int foo' is the parameter (indicating the function needs 1 int passed to it in order to work)
Let's say the function looks like this:
1 2 3 4
|
void func(int foo)
{
std::cout << "foo = " << foo;
}
|
Now when you call the function, you need to give it some value for 'foo'. This is done by putting the number in the parenthesis when you call it:
1 2 3 4 5
|
int main()
{
func(5); // this passes '5' as 'foo' in the function
// so it will print: "foo = 5"
}
|
If the function takes no parameters, then it takes no input. For example:
1 2 3 4
|
void func()
{
std::cout << "No input";
}
|
Now we don't need to give it any input when we call it, however we still need parenthesis to call it... so we call it like so:
1 2 3 4
|
int main()
{
func(); // calls func(), which prints "No input"
}
|
Returning values / output is another topic that I might explain later if nobody else does.