+ 2
What is meant by function prototype?
briefly explain it with instances.
4 odpowiedzi
+ 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 }
+ 7
^^@Hatsy Rei's answer, but just wait until you start doing function pointers, a whole new mindset will set in.
+ 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.
+ 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);