+ 3
Is it mandatory to use function declaration in C programming.If yes, please tell reason for that....
And also tell me.Why we are using the function declaration just above the main() function.What is a reason for that? And why we are using function definition below the main () function? Is there any reason behind it....? https://code.sololearn.com/c9GPv7wk6CDV/?ref=app //This code work very well.Without function declaration. This code also work well without warning .When I use function definition above the main() function.....// What is the reason behind it?😅
4 ответов
+ 2
C Compiler compiles a program from top to down and line by line. When it encounter a statement which is in using, then it binds to its declaration. So that's why first anything should be declare first then use it.
So it's need a function prototype if it is defined after the using statement...
So first defination then using is fine.
And adding prototype before main and defining function anywhere is also fine. But using it before declaration will give a error or warning..
+ 3
Thank you Azhagesan 🙌 bro
+ 2
Jayakrishna🇮🇳 thank you so much...🙌👍
+ 2
C programming follows top down approach. Which means if you call a function the compiler doesn't know The function exists or not. It only see top of the lines not below. So we need to define function prototype before main. Then we declare function anywhere in code.