+ 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!

8th May 2018, 5:37 PM
Akib
Akib - avatar
4 ответов
+ 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.
8th May 2018, 7:41 PM
Vlad Serbu
Vlad Serbu - avatar
+ 1
to connect functions in each other
9th May 2018, 6:19 PM
Seyedmm021
Seyedmm021 - avatar
0
Often you want to see the main function first at the top because thats what will be executed.
8th May 2018, 6:11 PM
TurtleShell
TurtleShell - avatar
0
If you want to use it.You should show them first.
9th May 2018, 9:11 AM
Shawn Li