+ 2

What is function prototype?

9th Nov 2016, 8:41 AM
Vaibhav kumar
Vaibhav kumar - avatar
4 Answers
+ 1
In C++ all functions must be declared before they are used. This is accomplished using function prototype. Prototypes enable complier to provide stronger type checking. When prototype is used, the compiler can find and report any illegal type conversions between the type of arguments used to call a function and the type definition of its parameters. It can also find the difference between the no of arguments used to call a function and the number of parameters in the function. Thus function prototypes help us trap bugs before they occur. In addition, they help verify that your program is working correctly by not allowing functions to be called with mismatched arguments.
9th Nov 2016, 1:58 PM
Gauri
0
function prototype is a statement which is used to notify the compiler of a function , it's return type, and the parameters before they defined usually later in the program after the main function. it can be easily spotted as a function but with a (;)at the end after the closing bracket
9th Nov 2016, 12:03 PM
Noob
Noob - avatar
0
A prototype simply means a function declaration above main (). if you define your main function at the top of your program then define other functions after the main function, you need to add your prototypes above main to make the function call in main understand that your prototype has a declaration somewhere in your source file. void buyFood (int); - Prototype void typeOfFood (string); - Prototype int main () { typeOfFood ("rice"); buyFood (10); getchar (); return 0; } void buyFood (int amount) { cout << "my food costs " << amount << " usd" << endl; } void typeOfFood (string food) { cout << "i am eating "<< food << endl; }
13th Nov 2016, 11:00 PM
𝐹𝓇𝒶𝓃𝓀𝓎 𝐵𝓇𝒶𝒾𝓃𝐵𝑜𝓍
𝐹𝓇𝒶𝓃𝓀𝓎 𝐵𝓇𝒶𝒾𝓃𝐵𝑜𝓍 - avatar
- 1
a function prototype or function interface is a declaration of a function that specifies the function's name and type but omits the function body. e.g. int add (int a, int b);
9th Nov 2016, 10:06 AM
Malvern Panashe Mhepo
Malvern Panashe Mhepo - avatar