where to place function body

In C++ programming language(using Dev-C++ compiler), by putting the body of function below the main function without the function header or prototype you will get an error.
int main(){

int s=sum(10,20);
return 0;
}

int sum(int a, int b){ //body of sum function

return(a+b);

}

There are two solutions :
1. Write function header or prototype above the main function
int sum(int a,int b); //place this line of c++ code above the main function
2. Write the body of the function above the main function

int sum(int a, int b){ //body of sum function

return(a+b);
}

int main(){

int s=sum(10,20);
return 0;
}

Posted by: mono | post date: 12-18-2012 | Subject: C++ Programming Language




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.