+ 2

What is meant by function prototype?

briefly explain it with instances.

10th Apr 2017, 1:10 PM
4 Answers
+ 13
// example void function (int); // this is the prototype int main() { //codes } void function(int param) // this is definition { //function body } --- --- The reason why we do this instead of putting function declaration and function definition on top of main is because, consider: void func1() { //codes } void func2() { //codes } int main() { //codes } func2 can access func1, but func1, which is on top of func2, cannot access func2. By declaring their prototypes on top of main and defining their innards later, functions get to access each other. void func1(); void func2(); int main() { //codes } void func1() { //codes } void func2() { //codes }
10th Apr 2017, 1:46 PM
Hatsy Rei
Hatsy Rei - avatar
+ 7
^^@Hatsy Rei's answer, but just wait until you start doing function pointers, a whole new mindset will set in.
10th Apr 2017, 8:13 PM
SoraKatadzuma - avatar
+ 4
By function prototype you can extends a class with a custom function and as extends means you benefit of all the class methods. I don't code in C++ but I guess that's the same as others languages.
10th Apr 2017, 1:13 PM
Geoffrey L
Geoffrey L - avatar
+ 2
before using a function we must declare it first, so function prototype contains it's type name and parameter.. e.g. int functionname (int a, int b);
10th Apr 2017, 3:13 PM
Abhijeet Singh
Abhijeet Singh - avatar