I'm following a guide to learn curses, and all of the C code within prototypes functions before main()
, then defines them afterward. In my C++ learnings, I had heard about function prototyping but never done it, and as far as I know it doesn't make too much of a difference on how the code is compiled. Is it a programmer's personal choice more than anything else? If so, why was it included in C at all?
In C prototyping is needed so that your program knows that you have a function called x()
when you have not gotten to defining it, that way y()
knows that there is and exists a x()
. C does top down compilation, so it needs to be defined before hand is the short answer.
x();
y();
main(){
}
y(){
x();
}
x(){
...
more code ...
maybe even y();
}