In a previous video, we went over the three aspects of functions. We also detailed function calls. In this episode, we will focus on the prototype aspect. In the course example, the example with the computation of the mean, the prototype the <i>moyenne</i> function is this line here ("moyenne" means "mean"). We will now examine prototypes in detail. In C++, just like variables, functions must be declared before they can be used. In the case of functions, this is known as a prototype. The prototype's purpose is to declare three things to the rest of the program: the name of the function, how it will be called; the parameters we must pass it, for the function to work; and finally, the return type, that is, the type of value that the function will return to the rest of the program. The general syntax of declaration of a prototype is as follows: first, we declare the return type, that the function will send to the rest of the program. Then, we provide the name of the function. And finally, between parentheses, is the list of all parameters that the function must receive in order to work. This list can be empty if the function does not need any parameters. As an example of a prototype, we can reuse the code example given in the previous slide, which is the mean calculation. Here, we will calculate the mean of two numbers. For that, let's say the function returns, to the rest of the program, a value of type "double", that it will be called "moyenne" ("mean") and that it will take two parameters: a parameter x of type double, and a parameter y of type double. We end the prototype declaration with a semicolon, ";". The part preceding the semicolon in a prototype, is what we call the "function header". And when the header is followed by a semicolon, then it is called a "prototype". The list of parameters can be empty. If, for example, we have a function which must ask the user for an integer, we could say that it must return an integer, that it must ask for a number. And to ask for a number, it doesn't need to receive any parameter. Now, the prototype will be as follows, with two empty parentheses and no list of parameters; simply two parentheses stuck together. The purpose of the prototype is to announce to the rest of the program what the function will do. For this purpose, the function must do only what it was designed to do. It must not have any hidden effects, what is known as "side effects". For example, if you imagine the square root function, which calculates the square root of a number, its prototype, as we can find it in the standard library, says that it expects an argument of type "double"; that it is called "sqrt", and that it returns a "double". You expect this function only to compute a square root value, and not to pollute the prompt with messages. These are known as "side effects". These are unexpected effects. Once we have clearly specified what the function must do, then we must choose a suitable name which illustrates exactly what the function does. Finally, a last piece of advice: always start by writing the prototype of a function. Writing the prototype of your function will allow you to clarify what parameters it must receive, as we have seen earlier, and also what it must provide, the type of what it must return. This way, you will already have specified two things before you even have to think about how you will implement what the function must do. Now, let's sum up the different aspects of the syntax that we have seen up til now in this lecture. If you write an expression which starts with a type, followed here by a name and a semicolon, then it is the declaration of a variable. However, if you add, between the name and the semicolon, some parentheses without arguments, then it will be the prototype of a function, and not a variable. This might seem a little more natural to you if I write it in this fashion here, int f(); Here, we can see more clearly, maybe because of its name, that it is a function. Or better yet, if I write, like in the previous example, the function "demande nb" ("ask number"), which doesn't take any arguments. Be very careful, this is indeed a function prototype. And it has nothing to do with a variable. This is a common mistake. If, however, between the parentheses, you enter a value which is compatible with the type which is at the beginning of the line, then you have a variable declaration again, and this time, with a value is also an initialization. So this line is actually very close to the first line. Here, we are simply adding a value for an initialization. And it has absolutely nothing to do with the second line. So be very careful with this sort of form. Finally, for a function call, if we put a name with no type in front, -- there is absolutely no type in front -- or we can have an "=" expression in front, for example z = a(5), but there is no type here, then it is of course a function call. It might have seemed more natural to you if I had written z = f(5). There, you naturally recognize a call to a function f. Or if I had written z = sqrt(2.0). There, you recognize a function call.