+ 1
Why function prototypes are declared
So, if I made a function above main() then I don't have any errors or anything. Why don't do that always? I mean what's the point of writing function below main and bother making a prototype on top!
4 Answers
+ 3
Imagine you have two functions foo() and bar() that want to call each other. If you put foo() on top, it won't know that bar() exists and will not be able to call it. If you put bar() it won't know that bar() exists and will not be able to call it.
Also headers. The standard library functions (like printf()) and objects (like cout) aren't stored as source code. They're stored as binary, so you don't compile them every time. Only a header containing their prototypes is stored as source code.
+ 1
to connect functions in each other
0
Often you want to see the main function first at the top because thats what will be executed.
0
If you want to use it.You should show them first.