+ 1
Does it matter if a user-defined function is defined before main() or after in C?
7 Answers
+ 3
If you define function after main() then you must provides it's prototype before main() first, ( so then after main , you can provide defination ). Otherwise compiler give you warnings...
+ 3
I personally prefer to first declare the functions (declaration is the same as prototype), then define the main() function and then define all the functions after main(). This is because if someone is reading your code, they can get the basic idea of what the functions do by looking at their prototypes and then go to the main() function without reading the, sometimes long/complex function definitions. This adds to the readability of the code as a whole
Note that this is only valid when you're working with only one file. When you're making bugger applications, you will give the function declarations in one file, define them in a separate file, and have the main() in another file.
+ 2
Its doesn't matter becz your execution always start from main function . but it will be good practice if u defining function prototype and if u want to save your time then make function before main in this case here you don't need to do prototyping.
+ 1
Thinking in the context of large programs :
Safer to use prototypes and it's a good practice for *larger* programs. Makes better readability. It's recommendations only..
0
Thank you for replying, so in conclusion is it safer to define function before main?