Quote:
Why use function prototypes instead of normal functions in C++?
Reason is rather simple: C/C++ compilers need to know exactly what are the parameters and return types of a function before using it.
So when a function is defined after using it, you need a prototype.
int average(int num1, int num2);
int main() {
cout << "enter two number: ";
int firstnum, secondnum;
cin >> firstnum >> secondnum;
cout << "average is: " << average(firstnum, secondnum);
return 0;
}
int average(int num1, int num2) {
return (num1 + num2) / 2;
}
if function is defined before using it, you don't need a prototype.