+ 2
What is the need of prototypes in c++ ?
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.
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;
}