This Question is about prototype in c++.
What is prototype in c++ please give me the structure and an example.?
A "protoype" is a statement that simply tells the program the format of a function call.
Let's say that you create a function that adds up two doubles:
double Add (double A, double B)
{
return A + B;
}
Now in the header file associated with this function you would insert a function prototype:
double Add (double A, double B);
which you will notice looks very much like the function declaration itself.
Why do you need to do this? It is simple actually. If you were to call the function "Add" in another file, this other file does not know what types the parameters are, and what type the return value is. In order for the compiler to do its job, it needs to know this information.
So you simply "#include" the header file with the prototype, and the prototype does not actually perform anything other than telling the compiler that the function has two parameters, both of type double, and that the function returns a double.
Hope this helps!
Reply:Looked it up on google and it gave me a result a www.about.com :
http://cplus.about.com/od/cprogrammin1/l...
hydrangea
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment