The compilation of the program starts from the first line arid next line and so on( i.e. line by line). While compiling the line cout<<sum(2,3); The compiler does not understand the word sum(2,3) because it is not declared yet hence the error prototype required.
To rectify this problem there are two methods
First method:
Give the function definition just before the main function as follows.
#include <iostream>
using namespace std;
int sum(intx, int y)
{return (x + y);}
int main()
{
cout<<sum(2,3);
}
Second Method:
Give the function declaration(prototype only) in the main function as follows.
#include<iostream>
using namespace std;
int main()
{
int sum(int.int);
cout<<sum(2,3);
}
int sum(int x, int y)
{return (x + y);}