+ 2

What is the need of prototypes in c++ ?

9th Nov 2016, 3:38 PM
Vaibhav kumar
Vaibhav kumar - avatar
2 ответов
0
when you are going to define Your Own function which is called user defined function so you use the prototype which tells the compiler that what is the type of your function and it also become the part of library and you can call your function to perform a particular task. for example: int grade(int) is a prototype which means I am taking the integer value and my function (grade) is returning an integer value.
10th Nov 2016, 7:28 PM
Ismail Zam Zam
Ismail Zam Zam - 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, 10:55 PM
Franky BrainBox
Franky BrainBox - avatar