Is it mandatory to use function declaration in C programming.If yes, please tell reason for that.... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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?😅

13th Oct 2020, 9:46 AM
Yogeshwaran P
Yogeshwaran P - avatar
4 Answers
+ 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..
13th Oct 2020, 11:31 AM
Jayakrishna 🇮🇳
+ 3
Thank you Azhagesan 🙌 bro
13th Oct 2020, 1:36 PM
Yogeshwaran P
Yogeshwaran P - avatar
+ 2
Jayakrishna🇮🇳 thank you so much...🙌👍
13th Oct 2020, 11:42 AM
Yogeshwaran P
Yogeshwaran P - avatar
+ 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.
13th Oct 2020, 1:35 PM
Azhagesanヾ(✿)
Azhagesanヾ(✿) - avatar