+ 1

Does it matter if a user-defined function is defined before main() or after in C?

13th May 2021, 5:54 PM
Anthony Asiimwe
Anthony Asiimwe - avatar
5 odpowiedzi
+ 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...
13th May 2021, 6:01 PM
Jayakrishna 🇮🇳
+ 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.
13th May 2021, 6:41 PM
XXX
XXX - avatar
+ 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.
13th May 2021, 6:16 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 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..
13th May 2021, 8:07 PM
Jayakrishna 🇮🇳
0
Thank you for replying, so in conclusion is it safer to define function before main?
13th May 2021, 6:07 PM
Anthony Asiimwe
Anthony Asiimwe - avatar